Browse Source

update: sub exit function

master
Dnomd343 2 years ago
parent
commit
b7d4861c0c
  1. 6
      kms.php
  2. 24
      src/Daemon.php

6
kms.php

@ -120,12 +120,14 @@ pcntl_signal(SIGCHLD, function() { // receive SIGCHLD signal
pcntl_signal(SIGTERM, function() { // receive SIGTERM signal
global $NGINX, $PHP_FPM, $VLMCSD;
logging::info('Get SIGTERM -> exit');
subExit($NGINX['pidFile'], $PHP_FPM['pidFile'], $VLMCSD['pidFile']);
subExit($NGINX, $PHP_FPM, $VLMCSD);
exit;
});
pcntl_signal(SIGINT, function() { // receive SIGINT signal
global $NGINX, $PHP_FPM, $VLMCSD;
logging::info('Get SIGINT -> exit');
subExit($NGINX['pidFile'], $PHP_FPM['pidFile'], $VLMCSD['pidFile']);
subExit($NGINX, $PHP_FPM, $VLMCSD);
exit;
});
logging::info('Loading kms-server (' . $VERSION . ')');

24
src/Daemon.php

@ -1,7 +1,5 @@
<?php
use JetBrains\PhpStorm\NoReturn;
require_once 'Logger.php';
require_once 'Process.php';
@ -48,18 +46,24 @@ function daemon(array $info): void {
}
}
#[NoReturn] function subExit(string $nginxPid, string $phpFpmPid, string $vlmcsdPid): void {
$nginxPid = getPid($nginxPid);
logging::info("Sending kill signal to nginx ($nginxPid)");
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);
$phpFpmPid = getPid($phpFpmPid);
logging::info("Sending kill signal to php-fpm ($phpFpmPid)");
$phpFpmName = $phpFpm['name'];
$phpFpmPid = getPid($phpFpm['pidFile']);
logging::info("Sending kill signal to $phpFpmName (PID = $phpFpmPid)");
posix_kill($phpFpmPid, SIGTERM);
$vlmcsdPid = getPid($vlmcsdPid);
logging::info("Sending kill signal to vlmcsd ($vlmcsdPid)");
$vlmcsdName = $vlmcsd['name'];
$vlmcsdPid = getPid($vlmcsd['pidFile']);
logging::info("Sending kill signal to $vlmcsdName (PID = $vlmcsdPid)");
posix_kill($vlmcsdPid, SIGTERM);
logging::info('Waiting sub process exit...');
pcntl_wait($status); // wait all process exit
logging::info('All process exit, Goodbye!');
exit;
}

Loading…
Cancel
Save