Skip to content

Commit 6242752

Browse files
authored
make ExecStop wait for pid to die (hestiacp#2772)
the previous ExecStop would send the TERM signal and return immidately. the new ExecStop will send SIGTERM then hang until the pid actually dies, similar to Debian/Ubuntu's "sudo sedvice hestia-php stop". sleep(0) is a neat little hack basically do the equivalent of pthread_yield(), turns the CPU usage from 100%-of-1-core to 15%-of-1-core, sleeping very fast.. which is required because there is a race condition here that is very hard to fix: if the pid is re-used between scans, we won't notice the pid has actually died and been resurrected. Even "killall -w" is suspectible to this race condition bug, and the fact that even GNU Coreutils's Killall have fixed it, is an indication that fixing this race condition bug is probably very difficult, the easiest course of action is probably to sleep very little, ie pthread_yield();
1 parent f835997 commit 6242752

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/rpm/php/hestia-php.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Type=forking
88
PIDFile=/var/run/hestia-php.pid
99
ExecStart=/usr/local/hestia/php/sbin/hestia-php --fpm-config /usr/local/hestia/php/etc/php-fpm.conf
1010
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /var/run/hestia-php.pid)"
11-
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/hestia-php.pid)"
11+
ExecStop=/usr/bin/php -r '$pid=(int)file_get_contents("/var/run/hestia-php.pid");posix_kill($pid,SIGTERM);while(posix_kill($pid,0)){sleep(0);}'
1212
ExecStartPre=/bin/bash -c "/bin/systemctl set-environment HOSTNAME=$(/usr/bin/hostname)"
1313
Environment="HESTIA=/usr/local/hestia"
1414

0 commit comments

Comments
 (0)