红联Linux门户
Linux帮助

centos 5.5 nginx 启动脚本

发布时间:2010-09-06 20:12:13来源:红联作者:堕落kiss
最近把blog换成了ngnix+php+mysql 感觉比apache占用资源少,很好用的东西.在次感谢tivon大哥的帮助...
1.建立脚本[code]vi /etc/init.d/nginxd[/code]2.更改权限[code]chmod 775 /etc/init.d/nginxd[/code]3,修改脚本[code]
#!/bin/bash
#
# chkconfig: - 85 15
# description: Nginx is a World Wide Web server.
# processname: nginx

nginx=/usr/local/nginx/sbin/nginx #更改成你的nginx的位置
conf=/usr/local/nginx/conf/nginx.conf #更改成你的nginx.conf的位置
case $1 in
start)
echo -n "Starting Nginx"
$nginx -c $conf
echo " done"
;;

stop)
echo -n "Stopping Nginx"
killall -9 nginx
echo " done"
;;

test)
$nginx -t -c $conf
;;

reload)
echo -n "Reloading Nginx"
ps auxww | grep nginx | grep master | awk '{print $2}' | xargs kill -HUP
echo " done"
;;

restart)
$0 stop
$0 start
;;

show)
ps -aux|grep nginx
;;

*)
echo -n "Usage: $0 {start|restart|reload|stop|test|show}"
;;

esac
[/code]到现在脚本建立好了,设置开机启动[code]chkconfig nginxd on[/code]下面是spawn-fcgi的启动脚本[code]#! /bin/sh
# chkconfig: - 85 15
# description: Spawn-fcgi is php-pmr app
DESC="spawn-fcgi daemon"
NAME=spawn-fcgi
DAEMON=/usr/local/bin/$NAME #更改成spawn-fcgi的位置,

# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0

d_start() {
$DAEMON -a 127.0.0.1 -p 9000 -C 10 -u www -g www -f /usr/local/php/bin/php-cgi > /dev/null 2>&1#-f 后面是php-cgi的位置
}

d_stop() {
/usr/bin/killall -9 php-cgi > /dev/null 2>&1 || echo -n " not running"
}

case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
exit 3
;;
esac

exit 0
[/code]
文章评论

共有 6 条评论

  1. olderlong 于 2010-10-07 14:45:01发表:

    Learning……
    Thanks

  2. william012 于 2010-10-03 18:15:55发表:

    这个是好东东

  3. blueseth 于 2010-09-28 20:25:54发表:

    路过瞧瞧...

  4. wst021 于 2010-09-11 08:56:45发表:

    {:2_92:} 楼的分享值得学习,顶起来!

  5. ml342418175 于 2010-09-07 16:37:56发表:

    :0)1

  6. yrgynot 于 2010-09-06 21:02:17发表:

    向楼主学习