From 93423e36af365439d55ccaa5e1cf96f055d88841 Mon Sep 17 00:00:00 2001 From: Beu Date: Fri, 1 Dec 2023 19:05:24 +0100 Subject: [PATCH] add support of process signals --- ManiaControl.php | 3 +++ core/ManiaControl.php | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/ManiaControl.php b/ManiaControl.php index 57bcf10a..25a659be 100644 --- a/ManiaControl.php +++ b/ManiaControl.php @@ -28,6 +28,9 @@ if (!ini_get('date.timezone') && function_exists('date_default_timezone_set')) { // Make sure garbage collection is enabled gc_enable(); +// Listen process signals +pcntl_async_signals(true); + // Register AutoLoader require_once MANIACONTROL_PATH . 'core' . DIRECTORY_SEPARATOR . 'AutoLoader.php'; \ManiaControl\AutoLoader::register(); diff --git a/core/ManiaControl.php b/core/ManiaControl.php index bba7f077..944c6488 100644 --- a/core/ManiaControl.php +++ b/core/ManiaControl.php @@ -652,6 +652,11 @@ class ManiaControl implements CallbackListener, CommandListener, TimerListener, Logger::log('Starting ManiaControl v' . self::VERSION . '!'); try { + // Manage SIGTERM signal + pcntl_signal(SIGTERM, function() { + $this->quit("Stop signal received from the OS.", false); + }); + // Connect to server $this->connect();