CentOS上可用的nginx启动脚本

 在网上找的脚本,挺好用的,已经用了一段时间了,怕以后配置新服务器还要再找所以记下来。

#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
# Taken from http://www.hikaro.com
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse 
#               proxy and IMAP/POP3 proxy server
# processname: nginx
# config:      /usr/local/nginx/conf/nginx.conf
# pidfile:     /usr/local/nginx/logs/nginx.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

nginx="/opt/nginx/sbin/nginx"
prog=$(basename $nginx)

NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"

lockfile=/var/lock/subsys/nginx

start() {
    [ -x $nginx ] || exit 5
    [ -f $NGINX_CONF_FILE ] || exit 6
    echo -n $"Starting $prog: "
    daemon $nginx -c $NGINX_CONF_FILE
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog -QUIT
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    configtest || return $?
    stop
    start
}

reload() {
    configtest || return $?
    echo -n $"Reloading $prog: "
    killproc $nginx -HUP
    RETVAL=$?
    echo
}

force_reload() {
    restart
}

configtest() {
  $nginx -t -c $NGINX_CONF_FILE
}

rh_status() {
    status $prog
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart|configtest)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
            ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
        exit 2
esac


 

CentOS上可以用的spawn-fcgi启动脚本

在网上找的支持chkconfig的spawn-fcgi启动脚本,原脚本大概是写给UNIX用的,使用的是socket文件的方式,结果启动后nginx连不上fcgi,导致PHP页面无法执行。

整好服务器后原文地址已经不知道哪里去了,真是对不起原作者。下面是在CentOS上实际测试好的启动脚本

#!/bin/sh
#
# Startup script for Spawn-fcgi
# chkconfig: - 85 15
# description: Start script for the php-fcgi
# processname: php-fcgi

FCGI_DAEMON="/opt/spawn-fcgi/bin/spawn-fcgi"
FCGI_PROGRAM="/opt/php/bin/php-cgi"
FCGI_SOCKET="/tmp/spawn-fcgi.sock"
FCGI_PIDFILE="/var/run/spawn-fcgi.pid"
PHP_FCGI_CHILDREN=4
PHP_FCGI_MAX_REQUESTS=1000

export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS

RETVAL=0
prog="spawn-fcgi"

# Source function library.
. /etc/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

start() {
        echo -n $"Starting $prog: "
        daemon $FCGI_DAEMON -a 127.0.0.1 -p 9000 -u www -g www -f $FCGI_PROGRAM -C $PHP_FCGI_CHILDREN -P $FCGI_PIDFILE
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: "
        rm -f $FCGI_PIDFILE $FCGI_SOCKET
        killproc $FCGI_PROGRAM
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
        return $RETVAL
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                start
                ;;
        condrestart)
                if [ -f /var/lock/subsys/$prog ]; then
                        stop
                        start
                fi
                ;;
        status)
                status $lighttpd
                RETVAL=$?
                ;;
        *)
                echo $"Usage: $0 {start|stop|restart|condrestart|status}"
                RETVAL=1
esac

exit $RETVAL


把上面代码保存为/etc/init.d/php-fcgi,使用以下命令把spawn-fcgi加入开机启动过程:

> chkconfig --add php-fcgi
> chkconfig --level 345 php-fcgi on


平时停止或者重启spawn-fcgi:

> service spawn-fcgi stop
> service spawn-fcgi start
> service spawn-fcgi restart


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值