From dd679a5ccdb51bf5e5168156d65800af324d8a32 Mon Sep 17 00:00:00 2001 From: Patrick Wuttke Date: Sat, 21 Aug 2021 11:55:54 +0200 Subject: [PATCH] Added portainerRestart function. --- portainer.js | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/portainer.js b/portainer.js index 0b9bb9f..4358122 100644 --- a/portainer.js +++ b/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"); }