1 <?php
2
3 /**
4 * Service handler
5 *
6 * @author Art <a.molcanovas@gmail.com>
7 */
8 abstract class Service {
9
10 /**
11 * Checks if a service exists
12 *
13 * @author Art <a.molcanovas@gmail.com>
14 *
15 * @param string $name Service name
16 *
17 * @return bool
18 */
19 static function exists($name) {
20 return trim(shell_exec(SERVICEEXISTS . ' ' . $name)) == 'OK';
21 }
22
23 /**
24 * Deletes a service
25 *
26 * @author Art <a.molcanovas@gmail.com>
27 *
28 * @param string $name Service name
29 *
30 * @return string shell_exec() output
31 */
32 static function delete($name) {
33 return self::stop($name) . PHP_EOL . shell_exec('sc delete ' . $name);
34 }
35
36 /**
37 * Stops a service
38 *
39 * @author Art <a.molcanovas@gmail.com>
40 *
41 * @param string $name Service name
42 *
43 * @return string shell_exec() output
44 */
45 static function stop($name) {
46 return shell_exec('sc stop ' . $name);
47 }
48
49 /**
50 * Starts a service
51 *
52 * @author Art <a.molcanovas@gmail.com>
53 *
54 * @param string $name Service name
55 *
56 * @return string shell_exec() output
57 */
58 static function start($name) {
59 return shell_exec('sc start ' . $name);
60 }
61
62 /**
63 * Installes a service from an executable
64 *
65 * @author Art <a.molcanovas@gmail.com>
66 *
67 * @param string $service_name The name of the service
68 * @param string $exe_path Path to the executable
69 * @param null|string $display_name Optionally, a custom display name for the service
70 *
71 * @return string shell_exec() output
72 */
73 static function installExe($service_name, $exe_path, $display_name = null) {
74 $cmd = 'sc create ' . $service_name . ' binPath= "' . $exe_path . '"';
75
76 if($display_name) {
77 $cmd .= ' DisplayName= "' . $display_name . '"';
78 }
79
80 return shell_exec($cmd);
81 }
82 }