vim /etc/init.d/nginx
#!/bin/bash
#chkconfig: 2345 80 90
#description: nginx
alter=$1
nginx=/usr/local/nginx/sbin/nginx
nginx_conf=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
. /etc/rc.d/init.d/functions
function if_info
{
if [ $2 == 0 ];then
echo -n "nginx $1 is ok!" && success && echo
else
echo -n "nginx $1 is error!" && success && echo
fi
}
case $alter in
start)
if [ -f $nginx_pid ];then
echo "nginx is already start!"
else
$nginx -c $nginx_conf
if_info start $?
fi
;;
stop)
if [ ! -f $nginx_pid ];then
echo "nginx is already stop!"
else
kill -TERM `cat $nginx_pid`
if_info stop $?
fi
;;
restart)
if [ ! -f $nginx_pid ];then
echo "nginx is stop,please start nginx!"
else
kill -HUP `cat $nginx_pid`
if_info restart $?
fi
;;
test)
$nginx -t -c $nginx_conf
# $nginx -t
if_info test $?
;;
status)
if [ ! -f $nginx_pid ];then
echo "nginx is stop"
else
echo "nginx is runing"
fi nginx
;;
*)
echo "Usage: $0 {start|stop|status|restart|test}"
;;
esac vim