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
This commit is contained in:
2018-01-12 13:32:01 +00:00
parent 6e10f2d9d4
commit 22b21450d2

View File

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