Linux论坛's Archiver

《开源》旗舰电子杂志2009年第1期火热下载!

jackbillow 发表于 2008-8-30 22:50

redhat或centos系统下nginx自动启动脚本(第二版)--原创

这一段时间给某地区的一个门户网站,部署了一个项目,为了利于他们以后的管理,以前写了第一个版,有写bug,这次重新完善了一下,应该比以前好用多了。:)nginx的启动关闭,能貌似是系统自带的服务:)
注意使用此脚本前,需要把nginx.conf里面pid修改到:/var/run/nginx.pid.

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# this script create it by jackbillow at 2007.10.15.
# it is v.0.0.2 version.
# if you find any errors on this scripts,please contact jackbillow.
# and send mail to jackbillow at gmail dot com.
#
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf

nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/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 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}


# 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
        ;;

reload)
        reload
        ;;

restart)
        stop
        start
        ;;

status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac

exit $RETVAL


vi /etc/init.d/nginx
输入上面的脚本的内容。
chmod a+x /etc/init.d/nginx
[root@jackbillow ~]# /etc/init.d/nginx stop
Stopping nginx:                                            [ OK ]
[root@jackbillow ~]# /etc/init.d/nginx start
Starting nginx:                                            [ OK ]
[root@jackbillow ~]# /etc/init.d/nginx restart
Stopping nginx:                                            [ OK ]
Starting nginx:                                            [ OK ]
[root@jackbillow ~]# /etc/init.d/nginx reload
Reloading nginx:                                           [ OK ]
[root@jackbillow ~]# /etc/init.d/nginx status
nginx (pid 22625 22624 22623 22622 22621 22620 22619 22618 22617 22616 22599) is running...
[root@jackbillow ~]#

fish2010 发表于 2008-8-31 18:31

支持一下

killer 发表于 2008-9-5 15:40

大善啊。 . .

页: [1]

Powered by Discuz! Archiver 7.0.0  © 2001-2009 Comsenz Inc.