Skip to content

Commit

Permalink
fix: stop when dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
JyJyJcr committed Dec 27, 2024
1 parent f9eef12 commit 900e3fc
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ pub struct Nginx {
http_uwsgi_temp_path: PathBuf,
http_scgi_temp_path: PathBuf,
// here all path are absolute
status: Status,
}

#[derive(PartialEq, Eq)]
enum Status {
Unknown,
Running,
Stopped,
}

/// nginx harness builder
Expand Down Expand Up @@ -179,6 +187,7 @@ impl NginxBuilder {
http_fastcgi_temp_path,
http_uwsgi_temp_path,
http_scgi_temp_path,
status: Status::Unknown,
}
}
}
Expand All @@ -202,12 +211,19 @@ impl Nginx {

/// complete stop the nginx binary
pub fn stop(&mut self) -> Result<Output> {
self.status = Status::Stopped;
self.cmd(&["-s", "stop"])
}

/// start the nginx binary
pub fn start(&mut self) -> Result<Output> {
self.cmd(&[])
let output = self.cmd(&[]);
if let Ok(output) = &output {
if output.status.success() {
self.status = Status::Running;
}
}
output
}

/// make sure we stop existing nginx and start new master process
Expand Down Expand Up @@ -336,3 +352,12 @@ impl Nginx {
&self.http_scgi_temp_path
}
}

impl Drop for Nginx {
fn drop(&mut self) {
// exec stop if running or unknown
if self.status != Status::Stopped {
let _ = self.stop();
}
}
}

0 comments on commit 900e3fc

Please sign in to comment.