1 | <?php |
||
18 | class Service |
||
19 | { |
||
20 | const STATUS_STOPPED = 3; |
||
21 | |||
22 | /** |
||
23 | * @var string |
||
24 | */ |
||
25 | private static $command = 'systemctl'; |
||
26 | |||
27 | /** |
||
28 | * @var bool |
||
29 | */ |
||
30 | private static $sudo = true; |
||
31 | |||
32 | /** |
||
33 | * @var int |
||
34 | */ |
||
35 | private static $timeout = 3; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | private $name; |
||
41 | |||
42 | /** |
||
43 | 65 | * Sets the systemctl command to use. |
|
44 | * |
||
45 | 65 | * @param string $command |
|
46 | 65 | */ |
|
47 | public static function setCommand($command) |
||
51 | |||
52 | /** |
||
53 | 65 | * Specifies whether or not to use sudo to run the systemctl command. |
|
54 | * |
||
55 | 65 | * @param bool $flag |
|
56 | 65 | */ |
|
57 | public static function sudo($flag = true) |
||
61 | 65 | ||
62 | /** |
||
63 | 65 | * Specifies the timeout in seconds for the systemctl process. |
|
64 | 65 | * |
|
65 | * @param int $timeout |
||
66 | */ |
||
67 | public static function setTimeout($timeout) |
||
71 | |||
72 | /** |
||
73 | 45 | * @param string $name Name of the service to manage |
|
74 | */ |
||
75 | 45 | public function __construct($name) |
|
79 | |||
80 | 45 | /** |
|
81 | * Checks whether or not the service is running. |
||
82 | 45 | * |
|
83 | 20 | * @throws CommandFailedException If the command failed |
|
84 | * |
||
85 | 25 | * @return bool |
|
86 | 20 | */ |
|
87 | public function isRunning() |
||
106 | 10 | ||
107 | /** |
||
108 | 10 | * Starts the service. |
|
109 | * |
||
110 | 10 | * @throws CommandFailedException If the command failed |
|
111 | 5 | */ |
|
112 | public function start() |
||
129 | 10 | ||
130 | /** |
||
131 | 10 | * Stops the service. |
|
132 | * |
||
133 | 10 | * @throws CommandFailedException If the command failed |
|
134 | 5 | */ |
|
135 | public function stop() |
||
152 | 15 | ||
153 | 10 | /** |
|
154 | * Restarts the service. |
||
155 | 5 | * |
|
156 | * @throws CommandFailedException If the command failed |
||
157 | */ |
||
158 | public function restart() |
||
171 | |||
172 | 60 | /** |
|
173 | 60 | * @return string |
|
174 | */ |
||
175 | public function __toString() |
||
179 | |||
180 | 60 | /** |
|
181 | * Creates and prepares a process. |
||
182 | * |
||
183 | * @param string[] $arguments |
||
184 | * |
||
185 | * @return Process |
||
186 | */ |
||
187 | private function getProcess(array $arguments) |
||
200 | } |
||
201 |