#!/bin/bash#chkconfig: 2345 30 88nginxd=/usr/local/nginx/sbin/nginx. /etc/init.d/functionsres=`netstat -lntup | grep nginx|wc -l`start(){ if [ $res -eq 0 ];then $nginxd -c /usr/local/nginx/conf/nginx.conf echo "nginx is starting" if [ $? -eq 0 ];then action "nginx is started." /bin/true else action "nginx is started." /bin/false fi else echo "nginx is running." fi}stop(){ if [ $res -ge 1 ];then $nginxd -s stop echo "nginx is stopping" if [ $? -eq 0 ];then action "nginx is stopped." /bin/true else action "nginx is stopped." /bin/false fi else echo "nginx is not running." fi}restart(){ if [ $res -ge 1 ];then killall -9 nginx action "nginx is stopped" /bin/true $nginxd -c /usr/local/nginx/conf/nginx.conf echo "nginx is starting." if [ $? -eq 0 ];then action "nginx is started." /bin/true else action "nginx is started." /bin/false fi else echo "ningx is not running." fi}case $1 in start) start ;; stop) stop ;; restart) restart ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1esacexit
将nginxd 加入启动项: chkconfig --add nginxd