@@ -69,15 +69,36 @@ public function executeStatusCommand() {
69
69
return 0 ;
70
70
}
71
71
72
- public function executeStopCommand () {
72
+ public function executeStopCommand ($ pids = null ) {
73
73
$ daemons = $ this ->loadRunningDaemons ();
74
74
if (!$ daemons ) {
75
75
echo "There are no running Phabricator daemons. \n" ;
76
76
return 0 ;
77
77
}
78
78
79
- $ running = $ daemons ;
79
+ $ daemons = mpull ( $ daemons, null , ' getPID ' ) ;
80
80
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 ();
81
102
foreach ($ running as $ key => $ daemon ) {
82
103
$ pid = $ daemon ->getPID ();
83
104
$ name = $ daemon ->getName ();
@@ -88,6 +109,7 @@ public function executeStopCommand() {
88
109
unset($ running [$ key ]);
89
110
} else {
90
111
posix_kill ($ pid , SIGINT );
112
+ $ killed [] = $ daemon ;
91
113
}
92
114
}
93
115
@@ -110,9 +132,10 @@ public function executeStopCommand() {
110
132
$ pid = $ daemon ->getPID ();
111
133
echo "KILLing daemon {$ pid }. \n" ;
112
134
posix_kill ($ pid , SIGKILL );
135
+ $ killed [] = $ daemon ;
113
136
}
114
137
115
- foreach ($ daemons as $ daemon ) {
138
+ foreach ($ killed as $ daemon ) {
116
139
if ($ daemon ->getPIDFile ()) {
117
140
Filesystem::remove ($ daemon ->getPIDFile ());
118
141
}
@@ -136,14 +159,12 @@ public function executeHelpCommand() {
136
159
**list**
137
160
List available daemons.
138
161
139
- **stop**
140
- Stop all daemons.
141
-
142
162
**status**
143
163
List running daemons.
144
164
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.
147
168
148
169
**help**
149
170
Show this help.
@@ -307,6 +328,4 @@ protected function loadRunningDaemons() {
307
328
protected function killDaemon (PhabricatorDaemonReference $ ref ) {
308
329
}
309
330
310
-
311
-
312
331
}
0 commit comments