@@ -86,6 +86,14 @@ pub struct Nginx {
8686 http_uwsgi_temp_path : PathBuf ,
8787 http_scgi_temp_path : PathBuf ,
8888 // here all path are absolute
89+ status : Status ,
90+ }
91+
92+ #[ derive( PartialEq , Eq ) ]
93+ enum Status {
94+ Unknown ,
95+ Running ,
96+ Stopped ,
8997}
9098
9199/// nginx harness builder
@@ -179,6 +187,7 @@ impl NginxBuilder {
179187 http_fastcgi_temp_path,
180188 http_uwsgi_temp_path,
181189 http_scgi_temp_path,
190+ status : Status :: Unknown ,
182191 }
183192 }
184193}
@@ -202,12 +211,19 @@ impl Nginx {
202211
203212 /// complete stop the nginx binary
204213 pub fn stop ( & mut self ) -> Result < Output > {
214+ self . status = Status :: Stopped ;
205215 self . cmd ( & [ "-s" , "stop" ] )
206216 }
207217
208218 /// start the nginx binary
209219 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
211227 }
212228
213229 /// make sure we stop existing nginx and start new master process
@@ -336,3 +352,12 @@ impl Nginx {
336352 & self . http_scgi_temp_path
337353 }
338354}
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