/
wreservice.pl
executable file
·167 lines (132 loc) · 5.26 KB
/
wreservice.pl
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/data/wre/prereqs/bin/perl
#-------------------------------------------------------------------
# WRE is Copyright 2005-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use lib '/data/wre/lib';
use strict;
use Getopt::Long;
use WRE::Config;
use WRE::Host;
use WRE::Starman;
use WRE::Nginx;
use WRE::Mysql;
use WRE::Spectre;
$|=1; # turn off buffering
my ($quiet, $help, $verbose) = "";
my (@start, @stop, @restart, @status) = ();
GetOptions(
"help" => \$help,
"start|begin=s{1,4}" => \@start,
"stop|end|shutdown=s{1,4}" => \@stop,
"restart|cycle=s{1,4}" => \@restart,
"status|ping=s{1,4}" => \@status,
"verbose" => \$verbose,
"quiet" => \$quiet,
);
if ($help || !(scalar(@start) || scalar(@stop) || scalar(@restart) || scalar(@status))) {
print <<STOP;
Usage: $0 --[action] [service] [service] [service]
Service Names:
all A shortcut that represents all the services.
starman The starman service which runs WebGUI.
nginx The nginx service which provides performance and security
services for WebGUI.
mysql WebGUI's database engine.
spectre WebGUI's workflow governor.
web A shortcut that represents both starman and nginx.
Actions:
--begin An alias for --start.
--end An alias for --stop.
--ping An alias for --status.
--restart Stops and then starts a service again.
--shutdown An alias for --stop.
--start Puts a service online.
--status Checks to see if a service is currently alive.
--stop Takes a service offline.
Options:
--help This message.
--quiet No output unless there's an error.
--verbose Print out additional information about failures.
STOP
}
my $config = WRE::Config->new;
my $host = WRE::Host->new(wreConfig => $config);
unless ($host->isPrivilegedUser || $quiet) {
print "\nWARNING: Because you are not an administrator on this system, you will not be able to
start or stop services on ports 1-1024.\n\n";
}
if (scalar(@stop)) {
if (grep /^spectre|all$/, @stop) {
printSuccess(sub{WRE::Spectre->new(wreConfig=>$config)->stop}, "Stop S.P.E.C.T.R.E.");
}
if (grep /^nginx|modproxy|all|web$/, @stop) {
printSuccess(sub{WRE::Nginx->new(wreConfig=>$config)->stop}, "Stop nginx");
}
if (grep /^starman|modperl|all|web$/, @stop) {
printSuccess(sub{WRE::Starman->new(wreConfig=>$config)->stop}, "Stop starman");
}
if (grep /^mysql|all$/, @stop) {
printSuccess(sub{WRE::Mysql->new(wreConfig=>$config)->stop}, "Stop MySQL");
}
}
if (scalar(@start)) {
if (grep /^mysql|all$/, @start) {
printSuccess(sub{WRE::Mysql->new(wreConfig=>$config)->start}, "Start MySQL");
}
if (grep /^starman|modperl|all|web$/, @start) {
printSuccess(sub{WRE::Starman->new(wreConfig=>$config)->start}, "Start starman");
}
if (grep /^nginx|modproxy|all|web$/, @start) {
printSuccess(sub{WRE::Nginx->new(wreConfig=>$config)->start}, "Start nginx");
}
if (grep /^spectre|all$/, @start) {
printSuccess(sub{WRE::Spectre->new(wreConfig=>$config)->start}, "Start S.P.E.C.T.R.E.");
}
}
if (scalar(@restart)) {
if (grep /^mysql|all$/, @restart) {
printSuccess(sub{WRE::Mysql->new(wreConfig=>$config)->restart}, "Restart MySQL");
}
if (grep /^starman|modperl|all|web$/, @restart) {
printSuccess(sub{WRE::Starman->new(wreConfig=>$config)->restart}, "Restart starman");
}
if (grep /^nginx|modproxy|all|web$/, @restart) {
printSuccess(sub{WRE::Nginx->new(wreConfig=>$config)->restart}, "Restart nginx");
}
if (grep /^spectre|all$/, @restart) {
printSuccess(sub{WRE::Spectre->new(wreConfig=>$config)->restart}, "Restart S.P.E.C.T.R.E.");
}
}
if (scalar(@status)) {
if (grep /^mysql|all$/, @status) {
printSuccess(sub{WRE::Mysql->new(wreConfig=>$config)->ping}, "Ping MySQL");
}
if (grep /^starman|modperl|all|web$/, @status) {
printSuccess(sub{WRE::Starman->new(wreConfig=>$config)->ping}, "Ping starman");
}
if (grep /^nginx|modproxy|all|web$/, @status) {
printSuccess(sub{WRE::Nginx->new(wreConfig=>$config)->ping}, "Ping nginx");
}
if (grep /^spectre|all$/, @status) {
printSuccess(sub{WRE::Spectre->new(wreConfig=>$config)->ping}, "Ping S.P.E.C.T.R.E.");
}
}
#-------------------------------------------------------------------
sub printSuccess {
my $action = shift;
my $description = shift;
print sprintf("%-22s", $description.":") unless ($quiet);
if (eval { &$action }) {
print "OK\n" unless ($quiet);
}
else {
print "FAILED!\n" unless ($quiet);
print "Additional information: ".$@."\n" if ($verbose);
}
}