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); + } }