Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

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

[复制链接]
jackbillow 发表于 2008-8-30 22:58:45 | 显示全部楼层 |阅读模式
以前写了第一个版,有写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 ~]#
myforever 发表于 2008-8-31 22:29:27 | 显示全部楼层
支持楼主



欢迎来“随点BBS”逛逛

www.b2tang.com

回复

使用道具 举报

soxy 发表于 2008-9-3 19:38:48 | 显示全部楼层
怎么不详细介绍一下呢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-11-18 22:45 , Processed in 0.024218 second(s), 3 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表