Skip to content

Commit ceceb47

Browse files
author
Evan Priestley
committed
Merge pull request phacility#65 from CodeBlock/master
D975
2 parents 1b85624 + 1057063 commit ceceb47

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

scripts/daemon/phabricator_daemon_launcher.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ function must_have_extension($ext) {
4545
exit($err);
4646

4747
case 'stop':
48-
$err = $control->executeStopCommand();
48+
$pass_argv = array_slice($argv, 2);
49+
$err = $control->executeStopCommand($pass_argv);
4950
exit($err);
5051

5152
case 'repository-launch-readonly':

src/infrastructure/daemon/control/PhabricatorDaemonControl.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,36 @@ public function executeStatusCommand() {
6969
return 0;
7070
}
7171

72-
public function executeStopCommand() {
72+
public function executeStopCommand($pids = null) {
7373
$daemons = $this->loadRunningDaemons();
7474
if (!$daemons) {
7575
echo "There are no running Phabricator daemons.\n";
7676
return 0;
7777
}
7878

79-
$running = $daemons;
79+
$daemons = mpull($daemons, null, 'getPID');
8080

81+
$running = array();
82+
if ($pids == null) {
83+
$running = $daemons;
84+
} else {
85+
// We were given a PID or set of PIDs to kill.
86+
foreach ($pids as $key => $pid) {
87+
if (empty($daemons[$pid])) {
88+
echo "{$pid} is not Phabricator-controlled. Not killing.\n";
89+
continue;
90+
} else {
91+
$running[] = $daemons[$pid];
92+
}
93+
}
94+
}
95+
96+
if (empty($running)) {
97+
echo "No daemons to kill.\n";
98+
return 0;
99+
}
100+
101+
$killed = array();
81102
foreach ($running as $key => $daemon) {
82103
$pid = $daemon->getPID();
83104
$name = $daemon->getName();
@@ -88,6 +109,7 @@ public function executeStopCommand() {
88109
unset($running[$key]);
89110
} else {
90111
posix_kill($pid, SIGINT);
112+
$killed[] = $daemon;
91113
}
92114
}
93115

@@ -110,9 +132,10 @@ public function executeStopCommand() {
110132
$pid = $daemon->getPID();
111133
echo "KILLing daemon {$pid}.\n";
112134
posix_kill($pid, SIGKILL);
135+
$killed[] = $daemon;
113136
}
114137

115-
foreach ($daemons as $daemon) {
138+
foreach ($killed as $daemon) {
116139
if ($daemon->getPIDFile()) {
117140
Filesystem::remove($daemon->getPIDFile());
118141
}
@@ -136,14 +159,12 @@ public function executeHelpCommand() {
136159
**list**
137160
List available daemons.
138161
139-
**stop**
140-
Stop all daemons.
141-
142162
**status**
143163
List running daemons.
144164
145-
**stop**
146-
Stop all running daemons.
165+
**stop** [PID ...]
166+
Stop all running daemons if no PIDs are given, or a particular
167+
PID or set of PIDs, if they are supplied.
147168
148169
**help**
149170
Show this help.
@@ -307,6 +328,4 @@ protected function loadRunningDaemons() {
307328
protected function killDaemon(PhabricatorDaemonReference $ref) {
308329
}
309330

310-
311-
312331
}

0 commit comments

Comments
 (0)