-
Notifications
You must be signed in to change notification settings - Fork 1
/
fphp.php
74 lines (64 loc) · 2.02 KB
/
fphp.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
if(exec('whoami')!='root'){
echo "please use root user to exe the script.";
exit;
}
require_once(__DIR__ .DIRECTORY_SEPARATOR.'Loader.php');//加载框架
use GetOptionKit\OptionCollection;
use GetOptionKit\OptionParser;
use GetOptionKit\OptionPrinter\ConsoleOptionPrinter;
$specs = new OptionCollection;
$specs->add('e|env?', "set env.name when start the rpc server,default value is product. \n example:-e=test");
$specs->add('s|start', 'start the rpc server');
$specs->add('t|stop', 'stop the rpc server');
$specs->add('r|restart', 'restart the rpc server');
$specs->add('h|help', 'show help document');
$printer = new ConsoleOptionPrinter;
$parser = new OptionParser($specs);
$help_document = "Enabled options: \n".$printer->render($specs);
$envName='';
$current_exe='';
try {
if($result = $parser->parse($argv))
{
if(count($result->keys)==0 && count($result->arguments)==0){
echo $help_document;
exit;
}
if(isset($result->keys['help'])){
echo $help_document;
exit;
}
foreach ($result->keys as $key => $spec) {
if($envName!='')
break;
switch (strtolower($key)){
case "env":
$envName = $spec->value;
break;
case "start":
$current_exe = $key;
break;
case "stop":
$current_exe = $key;
break;
case "restart":
$current_exe = $key;
break;
default:
echo $help_document;
exit;
}
}
if($current_exe=='start' || $current_exe=='restart'){
\Server\Ctl::$current_exe($envName);
}elseif($current_exe!='')
\Server\Ctl::$current_exe();
else
echo $help_document;
}else{
echo $help_document;
}
} catch( Exception $e ) {
echo $e->getMessage();
}