CentOS6 /etc/init.d/nginx

/etc/init.d/nginx

#!/bin/sh

#

# nginx        Startup script for nginx

#

# chkconfig: - 85 15

# processname: nginx

# config: /etc/nginx/nginx.conf

# config: /etc/sysconfig/nginx

# pidfile: /var/run/nginx.pid

# description: nginx is an HTTP and reverse proxy server

#

### BEGIN INIT INFO

# Provides: nginx

# Required-Start: $local_fs $remote_fs $network

# Required-Stop: $local_fs $remote_fs $network

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Short-Description: start and stop nginx

### END INIT INFO



# Source function library.

. /etc/rc.d/init.d/functions



if [ -L $0 ]; then

    initscript=`/bin/readlink -f $0`

else

    initscript=$0

fi



sysconfig=`/bin/basename $initscript`



if [ -f /etc/sysconfig/$sysconfig ]; then

    . /etc/sysconfig/$sysconfig

fi



# nginx 命令绝对目录

nginx=${NGINX-/home/sbin/nginx}

prog=`/bin/basename $nginx`

# nginx 配置文件

conffile=${CONFFILE-/home/nginx/nginx.conf}

lockfile=${LOCKFILE-/var/lock/subsys/nginx}

pidfile=${PIDFILE-/home/logs/nginx.pid}

SLEEPMSEC=${SLEEPMSEC-200000}

UPGRADEWAITLOOPS=${UPGRADEWAITLOOPS-5}

RETVAL=0



start() {

    echo -n $"Starting $prog: "



    daemon --pidfile=${pidfile} ${nginx} -c ${conffile}

    RETVAL=$?

    echo

    [ $RETVAL = 0 ] && touch ${lockfile}

    return $RETVAL

}



stop() {

    echo -n $"Stopping $prog: "

    killproc -p ${pidfile} ${prog}

    RETVAL=$?

    echo

    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}

}



reload() {

    echo -n $"Reloading $prog: "

    killproc -p ${pidfile} ${prog} -HUP

    RETVAL=$?

    echo

}



upgrade() {

    oldbinpidfile=${pidfile}.oldbin



    configtest -q || return

    echo -n $"Starting new master $prog: "

    killproc -p ${pidfile} ${prog} -USR2

    echo



    for i in `/usr/bin/seq $UPGRADEWAITLOOPS`; do

        /bin/usleep $SLEEPMSEC

        if [ -f ${oldbinpidfile} -a -f ${pidfile} ]; then

            echo -n $"Graceful shutdown of old $prog: "

            killproc -p ${oldbinpidfile} ${prog} -QUIT

            RETVAL=$?

            echo

            return

        fi

    done



    echo $"Upgrade failed!"

    RETVAL=1

}



configtest() {

    if [ "$#" -ne 0 ] ; then

        case "$1" in

            -q)

                FLAG=$1

                ;;

            *)

                ;;

        esac

        shift

    fi

    ${nginx} -t -c ${conffile} $FLAG

    RETVAL=$?

    return $RETVAL

}



rh_status() {

    status -p ${pidfile} ${nginx}

}



# See how we were called.

case "$1" in

    start)

        rh_status >/dev/null 2>&1 && exit 0

        start

        ;;

    stop)

        stop

        ;;

    status)

        rh_status

        RETVAL=$?

        ;;

    restart)

        configtest -q || exit $RETVAL

        stop

        start

        ;;

    upgrade)

        rh_status >/dev/null 2>&1 || exit 0

        upgrade

        ;;

    condrestart|try-restart)

        if rh_status >/dev/null 2>&1; then

            stop

            start

        fi

        ;;

    force-reload|reload)

        reload

        ;;

    configtest)

        configtest

        ;;

    *)

        echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}"

        RETVAL=2

esac



exit $RETVAL
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 第一章 Nginx简介 Nginx是什么 没有听过Nginx?那么一定听过它的“同行”Apache吧!Ngi...
    JokerW阅读 32,799评论 24 1,002
  • 1.编译依赖 gcc 环境,如果没有 gcc 环境,需要安装 gcc 命令:yum install gcc-c++...
    十二月的柒阅读 421评论 0 0
  • 近日,从ubuntu切换到centos6,所以暂时先使用yum安装来搭建php环境 参考了网上的一些文章:链接1h...
    MORESIR阅读 295评论 1 1
  • 1.安装依赖 [root@web src]# yum install pcre zlibopenssl -y 2....
    think_lonely阅读 573评论 0 1
  • 90年代后期,我在镇上初中上学,因离家太远,得住在学校。 我们住在能容纳几十人的大宿舍里,都是两个班级的男生合住一...
    轨伙阅读 1,760评论 0 1