forked from nginx/ngx-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add nginx instance module where you can start and stop nginx
sample test for instance
- Loading branch information
Sehyo Chang
committed
Sep 1, 2017
1 parent
3102b5a
commit acfc545
Showing
5 changed files
with
144 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#load_module modules/ngx_http_rust_module.so; | ||
|
||
#user nobody; | ||
worker_processes 1; | ||
|
||
error_log logs/error.log; | ||
#error_log logs/error.log notice; | ||
#error_log logs/error.log info; | ||
|
||
#pid logs/nginx.pid; | ||
|
||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
|
||
http { | ||
include mime.types; | ||
default_type application/octet-stream; | ||
|
||
|
||
# rust test; | ||
|
||
|
||
|
||
server { | ||
listen 8080; | ||
server_name localhost; | ||
|
||
#charset koi8-r; | ||
|
||
#access_log logs/host.access.log main; | ||
|
||
location / { | ||
root html; | ||
index index.html index.htm; | ||
} | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
pub mod bindings; | ||
pub mod nginx_http; | ||
|
||
pub mod nginx; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/** | ||
* harness to test nginx | ||
*/ | ||
|
||
use std::process::Command; | ||
use std::process::Output; | ||
use std::io::Result; | ||
use std::env; | ||
use std::fs; | ||
|
||
const NGINX_BIN: &str = "nginx/install/sbin/nginx"; | ||
|
||
pub struct Nginx { | ||
|
||
pub install_path: String // install path | ||
} | ||
|
||
|
||
impl Nginx { | ||
|
||
pub fn new(path: String) -> Nginx { | ||
Nginx { install_path: path } | ||
} | ||
|
||
// create nginx with default | ||
pub fn default() -> Nginx { | ||
let path = env::current_dir().unwrap(); | ||
let nginx_bin_path = format!("{}/{}",path.display(),NGINX_BIN); | ||
Nginx { install_path: nginx_bin_path} | ||
} | ||
|
||
|
||
pub fn cmd(&mut self, args: &[&str] ) -> Result<Output> { | ||
let result = Command::new(&self.install_path) | ||
.args(args) | ||
.output(); | ||
|
||
match result { | ||
Err(e) => { | ||
return Err(e); | ||
}, | ||
|
||
Ok(output) => { | ||
println!("status: {}", output.status); | ||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); | ||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); | ||
return Ok(output); | ||
} | ||
} | ||
|
||
} | ||
|
||
// complete stop the nginx binary | ||
pub fn stop(&mut self) -> Result<Output> { | ||
self.cmd(&["-s","stop"]) | ||
} | ||
|
||
// start the nginx binary | ||
pub fn start(&mut self) -> Result<Output> { | ||
self.cmd(&[]) | ||
} | ||
|
||
|
||
// make sure we stop existing nginx and start new master process | ||
// intentinally ignore failure in stop | ||
pub fn restart(&mut self) -> Result<Output> { | ||
|
||
self.stop(); | ||
self.start() | ||
} | ||
|
||
// replace config with another config | ||
pub fn replace_config(&mut self, path: &str) { | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters