@@ -86,6 +86,14 @@ pub struct Nginx {
86
86
http_uwsgi_temp_path : PathBuf ,
87
87
http_scgi_temp_path : PathBuf ,
88
88
// here all path are absolute
89
+ status : Status ,
90
+ }
91
+
92
+ #[ derive( PartialEq , Eq ) ]
93
+ enum Status {
94
+ Unknown ,
95
+ Running ,
96
+ Stopped ,
89
97
}
90
98
91
99
/// nginx harness builder
@@ -179,6 +187,7 @@ impl NginxBuilder {
179
187
http_fastcgi_temp_path,
180
188
http_uwsgi_temp_path,
181
189
http_scgi_temp_path,
190
+ status : Status :: Unknown ,
182
191
}
183
192
}
184
193
}
@@ -202,12 +211,19 @@ impl Nginx {
202
211
203
212
/// complete stop the nginx binary
204
213
pub fn stop ( & mut self ) -> Result < Output > {
214
+ self . status = Status :: Stopped ;
205
215
self . cmd ( & [ "-s" , "stop" ] )
206
216
}
207
217
208
218
/// start the nginx binary
209
219
pub fn start ( & mut self ) -> Result < Output > {
210
- self . cmd ( & [ ] )
220
+ let output = self . cmd ( & [ ] ) ;
221
+ if let Ok ( output) = & output {
222
+ if output. status . success ( ) {
223
+ self . status = Status :: Running ;
224
+ }
225
+ }
226
+ output
211
227
}
212
228
213
229
/// make sure we stop existing nginx and start new master process
@@ -336,3 +352,12 @@ impl Nginx {
336
352
& self . http_scgi_temp_path
337
353
}
338
354
}
355
+
356
+ impl Drop for Nginx {
357
+ fn drop ( & mut self ) {
358
+ // exec stop if running or unknown
359
+ if self . status != Status :: Stopped {
360
+ let _ = self . stop ( ) ;
361
+ }
362
+ }
363
+ }
0 commit comments