Make a container action tell the truth about what happened
The response was discarded, so a refused stop looked like a completed one, and the payload the card redraws from is cached for 300s with no invalidation — the container carried on showing as running until the once-a-minute writer caught up. Stop now confirms; start still does not.
This commit is contained in:
@@ -127,8 +127,15 @@ if ($check !== $name) {
|
||||
echo json_encode(['ok' => false, 'error' => 'Container not found']); exit;
|
||||
}
|
||||
|
||||
// Every arm below drops the monitor cache once the container state has actually changed. That
|
||||
// payload carries the container list the dashboard draws, is served with a 300s window, and is
|
||||
// otherwise only rewritten by the once-a-minute cache writer — so without this the operator stops
|
||||
// a container, watches the card, and sees it running for up to a minute with no hint as to why.
|
||||
// Cleared after the command rather than before, so a failed action does not throw away a payload
|
||||
// that is still accurate.
|
||||
if ($action === 'start' || $action === 'stop') {
|
||||
exec(($action === 'start' ? 'docker start' : 'docker stop') . ' ' . escapeshellarg($name) . ' 2>&1', $out, $rc);
|
||||
if ($rc === 0) vv_cache_clear('monitor');
|
||||
echo json_encode(['ok' => $rc === 0, 'output' => implode("\n", $out)]); exit;
|
||||
}
|
||||
|
||||
@@ -142,6 +149,7 @@ if ($action === 'restart') {
|
||||
$out = array_merge($o1, $o2);
|
||||
$rc = ($rc1 === 0 && $rc2 === 0) ? 0 : 1;
|
||||
}
|
||||
if ($rc === 0) vv_cache_clear('monitor');
|
||||
echo json_encode(['ok' => $rc === 0, 'output' => implode("\n", $out)]); exit;
|
||||
}
|
||||
|
||||
|
||||
@@ -92,6 +92,10 @@ if (PHP_SAPI !== 'cli') {
|
||||
|
||||
if (!$name || !$jobFile || !$image) exit(1);
|
||||
|
||||
// Only for vv_cache_clear() below. Required after the CLI guard, so a stray web request is turned
|
||||
// away before this process loads anything at all.
|
||||
require_once dirname(__DIR__) . '/include/config.php';
|
||||
|
||||
function jw(string $f, array $d): void { file_put_contents($f, json_encode($d)); }
|
||||
|
||||
shell_exec('docker pull ' . escapeshellarg($image) . ' 2>&1');
|
||||
@@ -115,6 +119,10 @@ if ($rebuild && is_executable($rebuild)) {
|
||||
$rc = ($rc1 === 0 && $rc2 === 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
// The container was stopped and started to get here whether or not the rebuild reported success,
|
||||
// so the cached container list is out of date either way.
|
||||
vv_cache_clear('monitor');
|
||||
|
||||
jw($jobFile, $rc === 0
|
||||
? ['ok' => true, 'status' => 'done', 'updated' => true, 'message' => 'Updated and rebuilt']
|
||||
: ['ok' => false, 'status' => 'done', 'error' => 'Rebuild failed after pull']
|
||||
|
||||
Reference in New Issue
Block a user