-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmanagementActions.php
51 lines (42 loc) · 1.32 KB
/
managementActions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* This file is part of Win32Service Library package
* @copy Win32Service (c) 2018-2019
* @author "MacintoshPlus" <macintoshplus@mactronique.fr>
*/
use Win32Service\Model\ServiceIdentifier;
use Win32Service\Service\ServiceStateManager;
include __DIR__.'/../vendor/autoload.php';
// Init the service identifier
$serviceId = ServiceIdentifier::identify(
isset($argv[2])? $argv[2]:'my_test_service', //By default use the service name 'my_test_service'
'localhost'
);
echo 'Service : '.$serviceId."\n";
$actions = ['start', 'stop', 'pause', 'continue'];
if (!isset($argv[1]) || !in_array($argv[1], $actions)) {
die("Usage ".$argv[0]." ".implode('|', $actions)." [serviceId]\n");
}
$actionManager = new ServiceStateManager();
try {
switch ($argv[1]) {
case 'start':
$actionManager->startService($serviceId);
break;
case 'stop':
$actionManager->stopService($serviceId);
break;
case 'pause':
$actionManager->pauseService($serviceId);
break;
case 'continue':
$actionManager->continueService($serviceId);
break;
default:
throw new \Exception("Unknown action ".$argv[1], 1);
break;
}
printf('The action %s is success', $argv[1]);
} catch(Exception $e) {
echo 'Error : ('.$e->getCode().') '.get_class($e).': '.$e->getMessage()."\n";
}