From 22b21450d26ffd14f9ee32be4e22e0491b4abf5c Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Fri, 12 Jan 2018 13:32:01 +0000 Subject: [PATCH] daemon: add reload method to send Kill -HUP to daemon git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4030 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- daemon.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/daemon.php b/daemon.php index a73613e..3b73451 100644 --- a/daemon.php +++ b/daemon.php @@ -145,4 +145,28 @@ class daemon } return "The daemon is running on PID $pid\n"; } + + /** Send a HUP Signal to the daemon + * @param string $name The name of daemon to HUP. The name must be + * the same as the name used in the start method + */ + public function reload ($name) + { + $file = new \file (); + if (! $file->is_writeable ($this->runDir)) + throw new \Exception (sprintf ("Run Directory '%s' is not writeable", + $this->runDir), 500); + if (! $file->is_readable ($this->runDir)) + throw new \Exception (sprintf ("Run Directory '%s' is not readable", + $this->runDir), 500); + if (! $file->file_exists ($this->runDir."/$name.pid")) + return "The daemon is be stopped"; + $pid = $file->file_get_contents ($this->runDir."/$name.pid"); + if (! file_exists ("/proc/$pid")) + { + $file->unlink ($this->runDir."/$name.pid"); + return "The daemon is stopped, but the PID file was remaining. Delete"; + } + return posix_kill ($pid, SIGHUP); + } }