Added portainerRestart function.
This commit is contained in:
parent
e181cef887
commit
dd679a5ccd
38
portainer.js
38
portainer.js
@ -64,7 +64,7 @@ async function portainerIsRunning(container)
|
||||
}
|
||||
}
|
||||
|
||||
async function portainerStart(container)
|
||||
async function portainerCmd(container, cmd)
|
||||
{
|
||||
let bearer = await portainerAuth();
|
||||
if (bearer == null)
|
||||
@ -74,7 +74,7 @@ async function portainerStart(container)
|
||||
|
||||
try
|
||||
{
|
||||
let req = new Request(portainerURL + "/api/endpoints/" + portainerEndpoint + "/docker/containers/" + container + "/start",
|
||||
let req = new Request(portainerURL + "/api/endpoints/" + portainerEndpoint + "/docker/containers/" + container + "/" + cmd,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {"Authorization": "Bearer " + bearer}
|
||||
@ -91,29 +91,17 @@ async function portainerStart(container)
|
||||
}
|
||||
}
|
||||
|
||||
async function portainerStart(container)
|
||||
{
|
||||
return await portainerCmd(container, "start");
|
||||
}
|
||||
|
||||
async function portainerStop(container)
|
||||
{
|
||||
let bearer = await portainerAuth();
|
||||
if (bearer == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
let req = new Request(portainerURL + "/api/endpoints/" + portainerEndpoint + "/docker/containers/" + container + "/stop",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {"Authorization": "Bearer " + bearer}
|
||||
});
|
||||
|
||||
let resp = await fetch(req);
|
||||
// there is no response ...
|
||||
return resp.status < 300;
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
console.log(e);
|
||||
return false;
|
||||
}
|
||||
return await portainerCmd(container, "stop");
|
||||
}
|
||||
|
||||
async function portainerRestart(container)
|
||||
{
|
||||
return await portainerCmd(container, "restart");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user