nginx启动脚本

2012年7月20日 发表评论 阅读评论

linux下所有服务的启动脚本大多大同不异。nginx也不例外。因为我在生产环境下的linux都是通过源码包安装的(有些linux版本里已经集成了nginx)。而每次启动都跑到安装路径里去启动我本人倒是习惯了。不过部门里那帮写代码的家伙们不习惯。所以只好也像其他服务一样,搞个启动脚本写到/etc/init.d里面了。脚本内容如下,比一般的流传版本多了个test的测试配置文件的功能。

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# chkconfig: - 85 15
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/App/nginx/sbin/nginx
nginx_config=/App/nginx/conf/nginx.conf
nginx_pid=/App/nginx/logs/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && /bin/rm -f /var/lock/subsys/nginx /App/nginx/logs/nginx.pid
}
# test nginx daemons functions.
test() {
        echo "test $nginx_config configure file "
        $nginxd -t
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
test)
        test
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|test|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL

 




本站的发展离不开您的资助,金额随意,欢迎来赏!

You can donate through PayPal.
My paypal id: itybku@139.com
Paypal page: https://www.paypal.me/361way

分类: http/html/web 标签:
  1. 2012年8月1日09:40 | #1

    Woot, I will certialny put this to good use!