1 | <?php |
||
19 | class Service |
||
20 | { |
||
21 | const STATUS_STOPPED = 3; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private static $command = 'systemctl'; |
||
27 | |||
28 | /** |
||
29 | * @var bool |
||
30 | */ |
||
31 | private static $sudo = true; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | private $name; |
||
37 | |||
38 | /** |
||
39 | * Sets the systemctl command to use. |
||
40 | * |
||
41 | * @param string $command |
||
42 | */ |
||
43 | 65 | public static function setCommand($command) |
|
47 | |||
48 | /** |
||
49 | * Specifies whether or not to use sudo to run the systemctl command. |
||
50 | * |
||
51 | * @param bool $flag |
||
52 | */ |
||
53 | 65 | public static function sudo($flag = true) |
|
57 | |||
58 | /** |
||
59 | * @param string $name Name of the service to manage |
||
60 | */ |
||
61 | 65 | public function __construct($name) |
|
65 | |||
66 | /** |
||
67 | * Checks whether or not the service is running. |
||
68 | * |
||
69 | * @throws CommandFailedException If the command failed |
||
70 | * |
||
71 | * @return bool |
||
72 | */ |
||
73 | 45 | public function isRunning() |
|
91 | |||
92 | /** |
||
93 | * Starts the service. |
||
94 | * |
||
95 | * @throws CommandFailedException If the command failed |
||
96 | */ |
||
97 | 15 | public function start() |
|
114 | |||
115 | /** |
||
116 | * Stops the service. |
||
117 | * |
||
118 | * @throws CommandFailedException If the command failed |
||
119 | */ |
||
120 | 15 | public function stop() |
|
137 | |||
138 | /** |
||
139 | * Restarts the service. |
||
140 | * |
||
141 | * @throws CommandFailedException If the command failed |
||
142 | */ |
||
143 | 15 | public function restart() |
|
156 | |||
157 | /** |
||
158 | * @return string |
||
159 | */ |
||
160 | 5 | public function __toString() |
|
164 | |||
165 | /** |
||
166 | * Creates and prepares a process builder. |
||
167 | * |
||
168 | * @return ProcessBuilder |
||
169 | */ |
||
170 | 60 | private function getProcessBuilder() |
|
182 | } |
||
183 |