1 | <?php |
||
17 | class Service |
||
18 | { |
||
19 | const STATUS_STOPPED = 3; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | private static $command = 'systemctl'; |
||
25 | |||
26 | /** |
||
27 | * @var bool |
||
28 | */ |
||
29 | private static $sudo = true; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $name; |
||
35 | |||
36 | /** |
||
37 | * Sets the systemctl command to use. |
||
38 | * |
||
39 | * @param string $command |
||
40 | */ |
||
41 | 52 | public static function setCommand($command) |
|
45 | |||
46 | /** |
||
47 | * Specifies whether or not to use sudo to run the systemctl command. |
||
48 | * |
||
49 | * @param bool $flag |
||
50 | */ |
||
51 | 52 | public static function sudo($flag = true) |
|
55 | |||
56 | /** |
||
57 | * @param string $name Name of the service to manage |
||
58 | */ |
||
59 | 52 | public function __construct($name) |
|
63 | |||
64 | /** |
||
65 | * Checks whether or not the service is running. |
||
66 | * |
||
67 | * @throws CommandFailedException If the command failed |
||
68 | * |
||
69 | * @return bool |
||
70 | */ |
||
71 | 36 | public function isRunning() |
|
89 | |||
90 | /** |
||
91 | * Starts the service. |
||
92 | * |
||
93 | * @throws CommandFailedException If the command failed |
||
94 | */ |
||
95 | 12 | public function start() |
|
112 | |||
113 | /** |
||
114 | * Stops the service. |
||
115 | * |
||
116 | * @throws CommandFailedException If the command failed |
||
117 | */ |
||
118 | 12 | public function stop() |
|
135 | |||
136 | /** |
||
137 | * Restarts the service. |
||
138 | * |
||
139 | * @throws CommandFailedException If the command failed |
||
140 | */ |
||
141 | 12 | public function restart() |
|
154 | |||
155 | /** |
||
156 | * @return string |
||
157 | */ |
||
158 | 4 | public function __toString() |
|
162 | |||
163 | /** |
||
164 | * Creates and prepares a process builder. |
||
165 | * |
||
166 | * @return ProcessBuilder |
||
167 | */ |
||
168 | 48 | private function getProcessBuilder() |
|
180 | } |
||
181 |