diff --git a/Dockerfile b/Dockerfile index 593bcb0..d19e910 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,7 +30,7 @@ COPY . /asset/kms-server/ RUN mkdir -p /asset/etc/ && mv /asset/kms-server/nginx/ /asset/etc/ FROM alpine:3.16 -RUN apk add --no-cache nginx php8 php8-fpm php8-iconv php8-pcntl +RUN apk add --no-cache nginx php8 php8-fpm php8-iconv php8-pcntl php8-posix COPY --from=asset /asset/ / EXPOSE 1688/tcp 1689/tcp WORKDIR /kms-server/ diff --git a/main.php b/main.php index 6932346..8aab9cd 100644 --- a/main.php +++ b/main.php @@ -1,15 +1,11 @@ 'nginx', 'command' => ['/usr/sbin/nginx'], @@ -28,13 +24,26 @@ $vlmcsd = array( 'pidFile' => '/run/vlmcsd.pid', ); -logging::info('Loading kms-server (' . $version . ')'); - 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, $phpFpm, $vlmcsd; + logging::info('Get SIGTERM -> exit'); + subExit($nginx['pidFile'], $phpFpm['pidFile'], $vlmcsd['pidFile']); +}); +pcntl_signal(SIGINT, function() { // receive SIGINT signal + global $nginx, $phpFpm, $vlmcsd; + logging::info('Get SIGINT -> exit'); + subExit($nginx['pidFile'], $phpFpm['pidFile'], $vlmcsd['pidFile']); +}); +if (in_array('--debug', $argv)) { // enter debug mode + logging::$logLevel = logging::DEBUG; +} + +logging::info('Loading kms-server (' . $version . ')'); new Process($nginx['command']); logging::info('Start nginx server...OK'); new Process($phpFpm['command']); @@ -42,9 +51,11 @@ logging::info('Start php-fpm server...OK'); new Process($vlmcsd['command']); logging::info('Start vlmcsd server...OK'); -logging::info('Enter the daemon process'); -while (true) { - msSleep(5000); // sleep 5s +logging::info('Enter daemon process'); +while (true) { // start daemon + for ($i = 0; $i < 500; $i++) { // sleep 5s + msDelay(10); // return main loop every 10ms + } daemon($nginx); daemon($phpFpm); daemon($vlmcsd); diff --git a/src/Daemon.php b/src/Daemon.php index c8f61aa..f223195 100644 --- a/src/Daemon.php +++ b/src/Daemon.php @@ -1,9 +1,11 @@