mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-25 16:22:43 +01:00
Stop 'stop' from being in phd's list twice, and provide a way to kill one particular PID.
Summary: This is a pretty bad, but working implmentation of a way to kill one particular PID that is controlled by Phabricator. Also remove the second 'stop' from the ##phd help## list. Test Plan: [ricky@rhelpad01 phabricator] (phd-stop-twice)$ ./bin/phd status PID Started Daemon 30154 Oct 1 2011, 2:38:08 AM PhabricatorMetaMTADaemon 30172 Oct 1 2011, 2:38:09 AM PhabricatorMetaMTADaemon 30190 Oct 1 2011, 2:38:09 AM PhabricatorMetaMTADaemon 30210 Oct 1 2011, 2:38:09 AM PhabricatorMetaMTADaemon [ricky@rhelpad01 phabricator] (phd-stop-twice)$ ./bin/phd stop 30190 Stopping daemon 'PhabricatorMetaMTADaemon' (30190)... Daemon 30190 exited normally. [ricky@rhelpad01 phabricator] (phd-stop-twice)$ ./bin/phd stop 123456 123456 is not controlled by Phabricator. Not killing. [ricky@rhelpad01 phabricator] (phd-stop-twice)$ ./bin/phd stop Stopping daemon 'PhabricatorMetaMTADaemon' (30154)... Stopping daemon 'PhabricatorMetaMTADaemon' (30172)... Stopping daemon 'PhabricatorMetaMTADaemon' (30210)... Daemon 30210 exited normally. Daemon 30154 exited normally. Daemon 30172 exited normally. Reviewers: epriestley CC: Differential Revision: 975
This commit is contained in:
parent
1b8562467c
commit
10570635b5
2 changed files with 31 additions and 11 deletions
|
@ -45,7 +45,8 @@ switch (isset($argv[1]) ? $argv[1] : 'help') {
|
||||||
exit($err);
|
exit($err);
|
||||||
|
|
||||||
case 'stop':
|
case 'stop':
|
||||||
$err = $control->executeStopCommand();
|
$pass_argv = array_slice($argv, 2);
|
||||||
|
$err = $control->executeStopCommand($pass_argv);
|
||||||
exit($err);
|
exit($err);
|
||||||
|
|
||||||
case 'repository-launch-readonly':
|
case 'repository-launch-readonly':
|
||||||
|
|
|
@ -69,15 +69,36 @@ final class PhabricatorDaemonControl {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function executeStopCommand() {
|
public function executeStopCommand($pids = null) {
|
||||||
$daemons = $this->loadRunningDaemons();
|
$daemons = $this->loadRunningDaemons();
|
||||||
if (!$daemons) {
|
if (!$daemons) {
|
||||||
echo "There are no running Phabricator daemons.\n";
|
echo "There are no running Phabricator daemons.\n";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$running = $daemons;
|
$daemons = mpull($daemons, null, 'getPID');
|
||||||
|
|
||||||
|
$running = array();
|
||||||
|
if ($pids == null) {
|
||||||
|
$running = $daemons;
|
||||||
|
} else {
|
||||||
|
// We were given a PID or set of PIDs to kill.
|
||||||
|
foreach ($pids as $key => $pid) {
|
||||||
|
if (empty($daemons[$pid])) {
|
||||||
|
echo "{$pid} is not Phabricator-controlled. Not killing.\n";
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
$running[] = $daemons[$pid];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($running)) {
|
||||||
|
echo "No daemons to kill.\n";
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$killed = array();
|
||||||
foreach ($running as $key => $daemon) {
|
foreach ($running as $key => $daemon) {
|
||||||
$pid = $daemon->getPID();
|
$pid = $daemon->getPID();
|
||||||
$name = $daemon->getName();
|
$name = $daemon->getName();
|
||||||
|
@ -88,6 +109,7 @@ final class PhabricatorDaemonControl {
|
||||||
unset($running[$key]);
|
unset($running[$key]);
|
||||||
} else {
|
} else {
|
||||||
posix_kill($pid, SIGINT);
|
posix_kill($pid, SIGINT);
|
||||||
|
$killed[] = $daemon;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,9 +132,10 @@ final class PhabricatorDaemonControl {
|
||||||
$pid = $daemon->getPID();
|
$pid = $daemon->getPID();
|
||||||
echo "KILLing daemon {$pid}.\n";
|
echo "KILLing daemon {$pid}.\n";
|
||||||
posix_kill($pid, SIGKILL);
|
posix_kill($pid, SIGKILL);
|
||||||
|
$killed[] = $daemon;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($daemons as $daemon) {
|
foreach ($killed as $daemon) {
|
||||||
if ($daemon->getPIDFile()) {
|
if ($daemon->getPIDFile()) {
|
||||||
Filesystem::remove($daemon->getPIDFile());
|
Filesystem::remove($daemon->getPIDFile());
|
||||||
}
|
}
|
||||||
|
@ -136,14 +159,12 @@ final class PhabricatorDaemonControl {
|
||||||
**list**
|
**list**
|
||||||
List available daemons.
|
List available daemons.
|
||||||
|
|
||||||
**stop**
|
|
||||||
Stop all daemons.
|
|
||||||
|
|
||||||
**status**
|
**status**
|
||||||
List running daemons.
|
List running daemons.
|
||||||
|
|
||||||
**stop**
|
**stop** [PID ...]
|
||||||
Stop all running daemons.
|
Stop all running daemons if no PIDs are given, or a particular
|
||||||
|
PID or set of PIDs, if they are supplied.
|
||||||
|
|
||||||
**help**
|
**help**
|
||||||
Show this help.
|
Show this help.
|
||||||
|
@ -307,6 +328,4 @@ EOHELP
|
||||||
protected function killDaemon(PhabricatorDaemonReference $ref) {
|
protected function killDaemon(PhabricatorDaemonReference $ref) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue