diff --git a/Makefile b/Makefile index 8ade3df..f9cd9c6 100644 --- a/Makefile +++ b/Makefile @@ -9,6 +9,17 @@ RUST_TOOL = gcr.io/$(GCLOUD_PROJECT)/ngx-rust-tool:${RUST_COMPILER_TAG} export ROOT_DIR=${PWD} + +darwin-build-nginx: + cd nginx/${DARWIN_NGINX}; \ + ./configure --prefix=${PWD}/nginx/install; \ + make; \ + make install + + +darwin-install-nginx: darwin-source darwin-configure + + setup-nginx: mkdir -p nginx diff --git a/config/nginx.conf b/config/nginx.conf new file mode 100644 index 0000000..8889ed7 --- /dev/null +++ b/config/nginx.conf @@ -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; + } + + + } + +} diff --git a/src/lib.rs b/src/lib.rs index 7a09f00..9a6afd9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,6 @@ pub mod bindings; pub mod nginx_http; - +pub mod nginx; diff --git a/src/nginx.rs b/src/nginx.rs new file mode 100644 index 0000000..5012b86 --- /dev/null +++ b/src/nginx.rs @@ -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 { + 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 { + self.cmd(&["-s","stop"]) + } + + // start the nginx binary + pub fn start(&mut self) -> Result { + self.cmd(&[]) + } + + + // make sure we stop existing nginx and start new master process + // intentinally ignore failure in stop + pub fn restart(&mut self) -> Result { + + self.stop(); + self.start() + } + + // replace config with another config + pub fn replace_config(&mut self, path: &str) { + + } + + +} + + + + + diff --git a/tests/log_test.rs b/tests/log_test.rs index c4327cb..6863e1d 100644 --- a/tests/log_test.rs +++ b/tests/log_test.rs @@ -1,16 +1,20 @@ extern crate ngx_rust; - #[cfg(test)] mod tests { + use std::env; + use ngx_rust::nginx::Nginx; + const NGINX_BIN: &str = "nginx/install/sbin/nginx"; #[test] fn test() { - assert_eq!(1,1); + let mut nginx = Nginx::default(); + let output = nginx.restart().expect("fail to start"); + assert!(output.status.success()); }