diff --git a/webui/plugins/podman/ajax/settings.php b/webui/plugins/podman/ajax/settings.php index 6848406..16b5314 100644 --- a/webui/plugins/podman/ajax/settings.php +++ b/webui/plugins/podman/ajax/settings.php @@ -86,6 +86,25 @@ switch ($action) { * @return array{running: bool, output: string} */ function rc_podman(string $verb, int $timeoutSeconds): array +{ + $output = run_rc_podman($verb, $timeoutSeconds); + + // Only `rc.podman status` prints the "service: running + // (pid ..., socket ...)" line this regex looks for — start/stop/ + // restart's OWN messages are worded differently ("start: already + // running (pid ...)", "stop: stopped", ...), so relying on THIS same + // regex against THEIR output silently reported "not running" right + // after a successful start (found live: a start that printed "start: + // already running" turned the status chip red). Always running a + // fresh `status` afterward — regardless of which verb was actually + // requested — is the one output format this check can trust. + $statusOutput = $verb === 'status' ? $output : run_rc_podman('status', 15); + $running = (bool) preg_match('/service:\s+running/', $statusOutput); + + return ['running' => $running, 'output' => $output]; +} + +function run_rc_podman(string $verb, int $timeoutSeconds): string { $descriptors = [1 => ['pipe', 'w'], 2 => ['pipe', 'w']]; $process = proc_open([RC_PODMAN, $verb], $descriptors, $pipes); @@ -100,13 +119,7 @@ function rc_podman(string $verb, int $timeoutSeconds): array fclose($pipes[2]); proc_close($process); - $combined = trim($stdout . $stderr); - // rc.podman status/start both print "service: running (pid ..., socket ...)" - // on success — cheaper and more honest than re-implementing the same - // socket/pid check PHP-side when the shell script already did it. - $running = (bool) preg_match('/service:\s+running/', $combined); - - return ['running' => $running, 'output' => $combined]; + return trim($stdout . $stderr); } /** @return array */