Added portainerRestart function.
This commit is contained in:
parent
0ab44a0f29
commit
d5af9eae93
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();
|
let bearer = await portainerAuth();
|
||||||
if (bearer == null)
|
if (bearer == null)
|
||||||
@ -74,7 +74,7 @@ async function portainerStart(container)
|
|||||||
|
|
||||||
try
|
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",
|
method: "POST",
|
||||||
headers: {"Authorization": "Bearer " + bearer}
|
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)
|
async function portainerStop(container)
|
||||||
{
|
{
|
||||||
let bearer = await portainerAuth();
|
return await portainerCmd(container, "stop");
|
||||||
if (bearer == null)
|
}
|
||||||
{
|
|
||||||
return false;
|
async function portainerRestart(container)
|
||||||
}
|
{
|
||||||
|
return await portainerCmd(container, "restart");
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user