From eeb202ea40957d6496c75ff9276cfce914bfb2e2 Mon Sep 17 00:00:00 2001 From: Divarion-D Date: Fri, 19 Jun 2026 22:33:41 +0300 Subject: [PATCH] Make service stop/restart reliably recycle the daemonized php-fpm The bundled php-fpm daemonizes out of systemd's cgroup, so a soft stop left masters (and their stale OPcache) alive after php.ini changes. Rewrite stop() to hard-kill by UID (escalating to SIGKILL, always returns 0), split boot() from the foreground start() so a manual `service restart` no longer holds the console, and guard the kill pipeline with xargs -r. --- src/service | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/service b/src/service index 40788b38..394d3c02 100644 --- a/src/service +++ b/src/service @@ -8,12 +8,9 @@ if [ "$USER" != "root" ]; then exit 0 fi -start() { - pids=$(pgrep -u xc_vm nginx | wc -l) - if [ $pids != 0 ]; then - echo 'XC_VM is already running' - return 1 - fi +# Launch every XC_VM service. Does NOT block — shared by start (foreground) and +# restart (returns to the shell). +boot() { echo 'Starting XC_VM...' sudo chown -R xc_vm:xc_vm /sys/class/net sudo chown -R xc_vm:xc_vm /home/xc_vm/content/streams @@ -29,6 +26,18 @@ start() { sudo -u xc_vm $SCRIPT/bin/php/bin/php $SCRIPT/console.php watchdog >/dev/null 2>/dev/null & sudo -u xc_vm $SCRIPT/bin/php/bin/php $SCRIPT/console.php queue >/dev/null 2>/dev/null & sudo -u xc_vm $SCRIPT/bin/php/bin/php $SCRIPT/console.php cache_handler >/dev/null 2>/dev/null & +} + +# Foreground entry for systemd (Type=simple): boot, then stay alive so systemd +# keeps tracking the unit. Holds the terminal BY DESIGN — for a manual, +# non-blocking restart use `restart` (or `systemctl restart|reload xc_vm`). +start() { + pids=$(pgrep -u xc_vm nginx | wc -l) + if [ $pids != 0 ]; then + echo 'XC_VM is already running' + return 1 + fi + boot echo 'Running in foreground...' sleep infinity } @@ -52,9 +61,10 @@ stop() { restart() { # Hard-recycle every xc_vm process EXCEPT ffmpeg (keeps active transcodes/ - # streams running) then start fresh — this is what reliably flushes OPcache. + # streams running) then boot fresh — reliably flushes OPcache. Returns to the + # shell; does NOT hold the console (boot, not the foreground start). ps -U xc_vm | egrep -v "ffmpeg|PID" | awk '{print $1}' | xargs -r kill -9 - start + boot } reload() {