@@ -26,6 +26,27 @@ WRE::Service
26
26
=cut
27
27
28
28
29
+ # -------------------------------------------------------------------
30
+
31
+ =head base ()
32
+
33
+ Get's the base command line invocation for this service and make sure that the user has permission
34
+ to start services.
35
+
36
+ /path/to/wre/nginx -c __NGINX_CONFIG__
37
+
38
+ =cut
39
+
40
+ sub base {
41
+ my $self = shift ;
42
+ my $wreConfig = $self -> wreConfig;
43
+ my $host = WRE::Host-> new(wreConfig => $wreConfig );
44
+ unless ($wreConfig -> get(" nginx/port" ) > 1024 || $host -> isPrivilegedUser) {
45
+ croak " You are not an administrator on this machine so you cannot start services with ports 1-1024." ;
46
+ }
47
+ return $wreConfig -> getRoot(" /prereqs/sbin/nginx" )." -c " .$wreConfig -> getRoot(" /etc/nginx.conf" );
48
+ }
49
+
29
50
# -------------------------------------------------------------------
30
51
31
52
=head getName ()
@@ -67,6 +88,32 @@ sub ping {
67
88
68
89
# -------------------------------------------------------------------
69
90
91
+ =head2 reload ( )
92
+
93
+ Makes nginx reload its configuration files without fully shutting down.
94
+
95
+ Returns a 1 if the start was successful, or a 0 if it was not.
96
+
97
+ Note: The process that runs this command must be either root or the user specified in the WRE config file.
98
+
99
+ =cut
100
+
101
+ sub reload {
102
+ my $self = shift ;
103
+ my $cmd = $self -> base . ' -s reload' ;
104
+ my $count = 0;
105
+ my $success = 0;
106
+ ` $cmd ` ; # catch command line output
107
+ while ($count < 10 && !$success ) {
108
+ sleep (1);
109
+ eval {$success = $self -> ping};
110
+ $count ++;
111
+ }
112
+ return $success ;
113
+ }
114
+
115
+ # -------------------------------------------------------------------
116
+
70
117
=head2 start ( )
71
118
72
119
Returns a 1 if the start was successful, or a 0 if it was not.
@@ -77,12 +124,7 @@ Note: The process that runs this command must be either root or the user specifi
77
124
78
125
sub start {
79
126
my $self = shift ;
80
- my $wreConfig = $self -> wreConfig;
81
- my $host = WRE::Host-> new(wreConfig => $wreConfig );
82
- unless ($wreConfig -> get(" nginx/port" ) > 1024 || $host -> isPrivilegedUser) {
83
- croak " You are not an administrator on this machine so you cannot start services with ports 1-1024." ;
84
- }
85
- my $cmd = $wreConfig -> getRoot(" /prereqs/sbin/nginx" )." -c " .$wreConfig -> getRoot(" /etc/nginx.conf" );
127
+ my $cmd = $self -> base;
86
128
my $count = 0;
87
129
my $success = 0;
88
130
` $cmd ` ; # catch command line output
@@ -109,12 +151,7 @@ Note: The process that runs this command must be either root or the user specifi
109
151
110
152
sub stop {
111
153
my $self = shift ;
112
- my $wreConfig = $self -> wreConfig;
113
- my $host = WRE::Host-> new(wreConfig => $wreConfig );
114
- unless ($wreConfig -> get(" nginx/port" ) > 1024 || $host -> isPrivilegedUser) {
115
- croak " You are not an administrator on this machine so you cannot stop services with ports 1-1024." ;
116
- }
117
- my $cmd = $wreConfig -> getRoot(" /prereqs/sbin/nginx" )." -c " .$wreConfig -> getRoot(" /etc/nginx.conf" )." -s stop" ;
154
+ my $cmd = $self -> base . " -s stop" ;
118
155
` $cmd ` ; # catch command line output
119
156
my $count = 0;
120
157
my $success = 0;
@@ -128,4 +165,25 @@ sub stop {
128
165
return $success ;
129
166
}
130
167
168
+ # -------------------------------------------------------------------
169
+
170
+ =head2 test ( )
171
+
172
+ Have nginx
173
+
174
+ Returns a 1 if the start was successful, or a 0 if it was not.
175
+
176
+ Note: The process that runs this command must be either root or the user specified in the WRE config file.
177
+
178
+ =cut
179
+
180
+ sub reload {
181
+ my $self = shift ;
182
+ my $cmd = $self -> base . ' -t' ;
183
+ my $out = ` $cmd ` ; # catch command line output
184
+ print $out ;
185
+ return 1;
186
+ }
187
+
188
+
131
189
1;
0 commit comments