nginx的服务自动启动文件

#! /bin/bash
#
# nginx      Start up the nginx server daemon
#
# chkconfig: 2345 55 25
# Description: starts and stops the nginx web server
#
### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Description:       starts and stops the nginx web server
### END INIT INFO

# To install:
#   copy this file to /etc/init.d/nginx
#   shell> chkconfig --add nginx (RedHat)
#   shell> update-rc.d -f nginx defaults (debian)

# To uninstall:
#   shell> chkconfig --del nginx (RedHat)
#   shell> update-rc.d -f nginx remove

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
NAME=nginx
DAEMON=/application/nginx/sbin/$NAME
CONFIGFILE=/application/nginx/conf/$NAME.conf
PIDFILE=/application/nginx/logs/$NAME.pid
ULIMIT=10240

 
set -e
[ -x "$DAEMON" ] || exit 0
 
do_start() {
    echo "Starting $NAME ..."
    ulimit -SHn $ULIMIT
    $DAEMON -c $CONFIGFILE
}

do_stop() {
    echo "Shutting down $NAME ..."
    kill `cat $PIDFILE`
}

do_reload() {
    echo "Reloading $NAME ..."
    kill -HUP `cat $PIDFILE`
}

case "$1" in
    start)
        [ ! -f "$PIDFILE" ] && do_start || echo "nginx already running"
    echo -e ".\ndone"
        ;;
    stop)
        [ -f "$PIDFILE" ] && do_stop || echo "nginx not running"
    echo -e ".\ndone"
        ;;
    restart)
        [ -f "$PIDFILE" ] && do_stop || echo "nginx not running"
        do_start
    echo -e ".\ndone"
        ;;
    reload)
        [ -f "$PIDFILE" ] && do_reload || echo "nginx not running"
    echo -e ".\ndone"
        ;;
    *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart|reload}" >&2
    exit 1
    ;;
esac

exit 0


下面对一些命令进行说明:
-H 设置硬资源限制,一旦设置不能增加。 ulimit – Hs 64;限制硬资源,线程栈大小为 64K。
-S 设置软资源限制,设置后可以增加,但是不能超过硬资源设置。 ulimit – Sn 32;限制软资源,32 个文件描述符。
-n 可以打开最大文件描述符的数量。 ulimit – n 128;限制最大可以使用 128 个文件描述符。

kill -HUP更改配置而不需停止并重新启动服务。















本文转自chenzudao51CTO博客,原文链接: http://blog.51cto.com/victor2016/1885092,如需转载请自行联系原作者




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值