mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Use the proc-error-aware signaling check for daemons from the CLI
Summary: The web console already correctly checks for processes which are running but can't be signaled. Share this check in the CLI. Test Plan: Looked at the web console. Poked at the CLI. Reviewed By: fratrik Reviewers: fratrik CC: aran, fratrik Differential Revision: 544
This commit is contained in:
parent
77bc35cde9
commit
709d7ed5d7
3 changed files with 20 additions and 10 deletions
|
@ -42,14 +42,8 @@ final class PhabricatorDaemonLogListView extends AphrontView {
|
|||
|
||||
if ($log->getHost() == php_uname('n')) {
|
||||
|
||||
// This will probably fail since apache can't signal the process, but
|
||||
// we can check the error code to figure out if the process exists.
|
||||
$is_running = posix_kill($log->getPID(), 0);
|
||||
if (posix_get_last_error() == 1) {
|
||||
// "Operation Not Permitted", indicates that the PID exists. If it
|
||||
// doesn't, we'll get an error 3 ("No such process") instead.
|
||||
$is_running = true;
|
||||
}
|
||||
$pid = $log->getPID();
|
||||
$is_running = PhabricatorDaemonReference::isProcessRunning($pid);
|
||||
|
||||
if ($is_running) {
|
||||
$running = phutil_render_tag(
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'infrastructure/daemon/control/reference');
|
||||
phutil_require_module('phabricator', 'view/base');
|
||||
phutil_require_module('phabricator', 'view/control/table');
|
||||
phutil_require_module('phabricator', 'view/utils');
|
||||
|
|
|
@ -55,11 +55,26 @@ final class PhabricatorDaemonReference {
|
|||
}
|
||||
|
||||
public function isRunning() {
|
||||
$pid = $this->getPID();
|
||||
return self::isProcessRunning($this->getPID());
|
||||
}
|
||||
|
||||
public static function isProcessRunning($pid) {
|
||||
if (!$pid) {
|
||||
return false;
|
||||
}
|
||||
return posix_kill($pid, 0);
|
||||
|
||||
// This may fail if we can't signal the process because we are running as
|
||||
// a different user (for example, we are 'apache' and the process is some
|
||||
// other user's, or we are a normal user and the process is root's), but
|
||||
// we can check the error code to figure out if the process exists.
|
||||
$is_running = posix_kill($pid, 0);
|
||||
if (posix_get_last_error() == 1) {
|
||||
// "Operation Not Permitted", indicates that the PID exists. If it
|
||||
// doesn't, we'll get an error 3 ("No such process") instead.
|
||||
$is_running = true;
|
||||
}
|
||||
|
||||
return $is_running;
|
||||
}
|
||||
|
||||
public function waitForExit($seconds) {
|
||||
|
|
Loading…
Reference in a new issue