1
1
<?php
2
2
3
- final class PhabricatorDaemonReference extends Phobject {
4
-
5
- private $ name ;
6
- private $ argv ;
7
- private $ pid ;
8
- private $ start ;
9
- private $ pidFile ;
10
-
11
- private $ daemonLog ;
12
-
13
- public static function loadReferencesFromFile ($ path ) {
14
- $ pid_data = Filesystem::readFile ($ path );
15
-
16
- try {
17
- $ dict = phutil_json_decode ($ pid_data );
18
- } catch (PhutilJSONParserException $ ex ) {
19
- $ dict = array ();
20
- }
21
-
22
- $ refs = array ();
23
- $ daemons = idx ($ dict , 'daemons ' , array ());
24
-
25
- $ logs = array ();
26
-
27
- $ daemon_ids = ipull ($ daemons , 'id ' );
28
- if ($ daemon_ids ) {
29
- try {
30
- $ logs = id (new PhabricatorDaemonLogQuery ())
31
- ->setViewer (PhabricatorUser::getOmnipotentUser ())
32
- ->withDaemonIDs ($ daemon_ids )
33
- ->execute ();
34
- } catch (AphrontQueryException $ ex ) {
35
- // Ignore any issues here; getting this information only allows us
36
- // to provide a more complete picture of daemon status, and we want
37
- // these commands to work if the database is inaccessible.
38
- }
39
-
40
- $ logs = mpull ($ logs , null , 'getDaemonID ' );
41
- }
42
-
43
- // Support PID files that use the old daemon format, where each overseer
44
- // had exactly one daemon. We can eventually remove this; they will still
45
- // be stopped by `phd stop --force` even if we don't identify them here.
46
- if (!$ daemons && idx ($ dict , 'name ' )) {
47
- $ daemons = array (
48
- array (
49
- 'config ' => array (
50
- 'class ' => idx ($ dict , 'name ' ),
51
- 'argv ' => idx ($ dict , 'argv ' , array ()),
52
- ),
53
- ),
54
- );
55
- }
56
-
57
- foreach ($ daemons as $ daemon ) {
58
- $ ref = new PhabricatorDaemonReference ();
59
-
60
- // NOTE: This is the overseer PID, not the actual daemon process PID.
61
- // This is correct for checking status and sending signals (the only
62
- // things we do with it), but might be confusing. $daemon['pid'] has
63
- // the daemon PID, and we could expose that if we had some use for it.
64
-
65
- $ ref ->pid = idx ($ dict , 'pid ' );
66
- $ ref ->start = idx ($ dict , 'start ' );
67
-
68
- $ config = idx ($ daemon , 'config ' , array ());
69
- $ ref ->name = idx ($ config , 'class ' );
70
- $ ref ->argv = idx ($ config , 'argv ' , array ());
71
-
72
- $ log = idx ($ logs , idx ($ daemon , 'id ' ));
73
- if ($ log ) {
74
- $ ref ->daemonLog = $ log ;
75
- }
76
-
77
- $ ref ->pidFile = $ path ;
78
- $ refs [] = $ ref ;
79
- }
80
-
81
- return $ refs ;
82
- }
3
+ // TODO: See T13321. After the removal of daemon PID files this class
4
+ // no longer makes as much sense as it once did.
83
5
84
- public function updateStatus ($ new_status ) {
85
- if (!$ this ->daemonLog ) {
86
- return ;
87
- }
88
-
89
- try {
90
- $ this ->daemonLog
91
- ->setStatus ($ new_status )
92
- ->save ();
93
- } catch (AphrontQueryException $ ex ) {
94
- // Ignore anything that goes wrong here.
95
- }
96
- }
97
-
98
- public function getPID () {
99
- return $ this ->pid ;
100
- }
101
-
102
- public function getName () {
103
- return $ this ->name ;
104
- }
105
-
106
- public function getArgv () {
107
- return $ this ->argv ;
108
- }
109
-
110
- public function getEpochStarted () {
111
- return $ this ->start ;
112
- }
113
-
114
- public function getPIDFile () {
115
- return $ this ->pidFile ;
116
- }
117
-
118
- public function getDaemonLog () {
119
- return $ this ->daemonLog ;
120
- }
121
-
122
- public function isRunning () {
123
- return self ::isProcessRunning ($ this ->getPID ());
124
- }
6
+ final class PhabricatorDaemonReference extends Phobject {
125
7
126
8
public static function isProcessRunning ($ pid ) {
127
9
if (!$ pid ) {
@@ -148,15 +30,4 @@ public static function isProcessRunning($pid) {
148
30
return $ is_running ;
149
31
}
150
32
151
- public function waitForExit ($ seconds ) {
152
- $ start = time ();
153
- while (time () < $ start + $ seconds ) {
154
- usleep (100000 );
155
- if (!$ this ->isRunning ()) {
156
- return true ;
157
- }
158
- }
159
- return !$ this ->isRunning ();
160
- }
161
-
162
33
}
0 commit comments