一个用于自编译nginx时写入service的脚本。
#!/bin/sh
nginx=/usr/local/nginx/sbin/nginx
conf=/usr/local/nginx/conf/nginx.conf
ngfunc () {
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done"
;;
stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done"
;;
test)
$nginx -t -c $conf
;;
reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done"
;;
restart)
ngfunc stop && sleep 1 && ngfunc start
;;
show)
ps -aux|grep nginx | grep -v grep | grep -v 'rc.d'
;;
*)
echo -n "Usage: $0 {start|restart|reload|stop|test|show}"
;;
esac
}
ngfunc $1