From e7acfc051dcca7de8902f78ad9f3bbdd66948f79 Mon Sep 17 00:00:00 2001 From: Austin Best Date: Thu, 3 Oct 2024 18:02:28 -0400 Subject: [PATCH] Add a restart container endpoint that also restarts dependencies --- root/app/www/public/functions/api.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/root/app/www/public/functions/api.php b/root/app/www/public/functions/api.php index 1e31288..1146ea3 100644 --- a/root/app/www/public/functions/api.php +++ b/root/app/www/public/functions/api.php @@ -397,6 +397,32 @@ function apiRequestLocal($endpoint, $parameters = [], $payload = []) } return $docker->removeNetwork($payload['id']); + case 'docker-restartContainer': + if (!$payload['name']) { + apiResponse(400, ['error' => 'Missing name parameter']); + } + + $dependencyFile = getFile(DEPENDENCY_FILE); + $dependencies = $dependencyFile[$payload['name']]['containers']; + $dependencies = is_array($dependencies) ? $dependencies : []; + + $stopContainer = $docker->stopContainer($payload['name']); + $return[] = 'docker-stopContainer: ' . json_encode($stopContainer, JSON_UNESCAPED_SLASHES); + $startContainer = $docker->startContainer($payload['name']); + $return[] = 'docker-startContainer: ' . json_encode($startContainer, JSON_UNESCAPED_SLASHES); + + if ($dependencies) { + $return[] = 'restarting dependenices...'; + + foreach ($dependencies as $dependency) { + $stopContainer = $docker->stopContainer($dependency); + $return[] = 'docker-stopContainer: ' . json_encode($stopContainer, JSON_UNESCAPED_SLASHES); + $startContainer = $docker->startContainer($dependency); + $return[] = 'docker-startContainer: ' . json_encode($startContainer, JSON_UNESCAPED_SLASHES); + } + } + + return $return; case 'docker-startContainer': if (!$payload['name']) { apiResponse(400, ['error' => 'Missing name parameter']);