Added portainerRestart function.

This commit is contained in:
Patrick 2021-08-21 11:55:54 +02:00
parent 0ab44a0f29
commit d5af9eae93
Signed by: mewin
GPG Key ID: CEDB412C39B5BC47

View File

@ -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;
return await portainerCmd(container, "stop");
}
try
async function portainerRestart(container)
{
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, "restart");
}