Browse Source

update: loop for multi-sub exit

master
Dnomd343 2 years ago
parent
commit
0e5de198a8
  1. 4
      kms.php
  2. 20
      src/Daemon.php

4
kms.php

@ -1,7 +1,7 @@
#!/usr/bin/env php8
<?php
$VERSION = 'v1.2.2';
$VERSION = 'v1.2.3';
require_once './src/Daemon.php';
require_once './src/Logger.php';
@ -117,12 +117,14 @@ declare(ticks = 1);
pcntl_signal(SIGCHLD, function() { // receive SIGCHLD signal
pcntl_wait($status, WNOHANG); // avoid zombie process
});
pcntl_signal(SIGTERM, function() { // receive SIGTERM signal
global $NGINX, $PHP_FPM, $VLMCSD;
logging::info('Get SIGTERM -> exit');
subExit($NGINX, $PHP_FPM, $VLMCSD);
exit;
});
pcntl_signal(SIGINT, function() { // receive SIGINT signal
global $NGINX, $PHP_FPM, $VLMCSD;
logging::info('Get SIGINT -> exit');

20
src/Daemon.php

@ -48,20 +48,12 @@ function daemon(array $info): void {
function subExit(array $nginx, array $phpFpm, array $vlmcsd): void {
$nginxName = $nginx['name'];
$nginxPid = getPid($nginx['pidFile']);
logging::info("Sending kill signal to $nginxName (PID = $nginxPid)");
posix_kill($nginxPid, SIGTERM);
$phpFpmName = $phpFpm['name'];
$phpFpmPid = getPid($phpFpm['pidFile']);
logging::info("Sending kill signal to $phpFpmName (PID = $phpFpmPid)");
posix_kill($phpFpmPid, SIGTERM);
$vlmcsdName = $vlmcsd['name'];
$vlmcsdPid = getPid($vlmcsd['pidFile']);
logging::info("Sending kill signal to $vlmcsdName (PID = $vlmcsdPid)");
posix_kill($vlmcsdPid, SIGTERM);
foreach (array($nginx, $phpFpm, $vlmcsd) as $subFunc) {
$subName = $subFunc['name'];
$subPid = getPid($subFunc['pidFile']);
logging::info("Sending kill signal to $subName (PID = $subPid)");
posix_kill($subPid, SIGTERM);
}
logging::info('Waiting sub process exit...');
pcntl_wait($status); // wait all process exit

Loading…
Cancel
Save