编写 Nginx 启动脚本

今天试了一下直接使用 php-cgi 启用 fastcgi 的脚本竟然又可以使用了,真奇怪。
写了一个自动启动脚本,放到这里做个备份:

#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or
# later
# $Header:$

NGINX_EXEC=/usr/sbin/nginx
PHP_EXEC=/usr/bin/php-cgi

depend() {
need logger net
}

start () {
ebegin "Starting FCGI Service"
spawn-fcgi -a 127.0.0.1 -p 9000 -C 5 -f /usr/bin/php-cgi
eend $?
ebegin "Starting Nginx"
start-stop-daemon --start --exec ${NGINX_EXEC}
eend $?
}

stop() {
ebegin "Stopping FCGI Service"
killall php-cgi
eend $?
ebegin "Stopping Nginx"
killall nginx
start-stop-daemon --stop --quiet --pidfile /var/run/nginx.pid
--exec $NGINX_EXEC
eend $?
}

然后把这个文件保存为 /etc/init.d/httpd 并加上执行权限。
然后运行 rc-config add httpd default

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>