以下是我写的控制nginx启动的,关闭,重启的shell脚本,经测试,在Solaris 10 系统下可以正常运行,不过这个脚本需要由超级用户执行。
以下代码片段的漂亮边框和背景是在秀代码这个网站弄的,呵呵。http://xiudaima.appspot.com/
BASH CODE :nginxControl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #!/usr/bin/sh NGINX_HOME=/usr/local/nginx if [ -n "$1" ] then case $1 in 1) echo "startup nginx" if [ -n "$2" ] then $NGINX_HOME/sbin/nginx -c "$2" echo "started" else echo "should have the second argument" fi ;; 2) echo "reload nginx" read nginx_pid < $NGINX_HOME/logs/nginx.pid echo "the main pid of nginx is $nginx_pid" echo "restart nginx now" kill -HUP $nginx_pid echo "restarted" ;; 3) echo "shut down nginx" read nginx_pid < $NGINX_HOME/logs/nginx.pid echo "the main pid of nginx is $nginx_pid" echo "shut down nginx now" kill -TERM $nginx_pid echo "shut down" ;; *) echo "error argument." ;; esac else echo "no arguments,should be one argument." exit 1 fi |