nginx启动脚本

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
[ -xnginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n"Starting prog: "
   daemonnginxd -c {nginx_config}
   RETVAL=?
   echo
   [ RETVAL = 0 ] && touch /var/lock/subsys/nginx
   returnRETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n "Stoppingprog: "
        killproc nginxd
        RETVAL=?
        echo
        [ RETVAL = 0 ] && /bin/rm -f /var/lock/subsys/nginx /App/nginx/logs/nginx.pid
}
# test nginx daemons functions.
test() {
        echo "testnginx_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)
        statusprog
        RETVAL=?
        ;;
*)
        echo"Usage: prog {start|stop|test|restart|reload|status|help}"
        exit 1
esac
exitRETVAL

 

nginx启动脚本》有1条评论

Dinesh进行回复 取消回复

您的电子邮箱地址不会被公开。