Skip to content

Commit

Permalink
Add a restart container endpoint that also restarts dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
austinwbest committed Oct 3, 2024
1 parent 16e61ab commit e7acfc0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions root/app/www/public/functions/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit e7acfc0

Please sign in to comment.