CentOS上可用的nginx启动脚本

配置新服务器:

[cpp]  view plain copy
  1. #!/bin/sh  
  2. #  
  3. # nginx - this script starts and stops the nginx daemin  
  4. # Taken from http://www.hikaro.com  
  5. # chkconfig:   - 85 15  
  6. # description:  Nginx is an HTTP(S) server, HTTP(S) reverse   
  7. #               proxy and IMAP/POP3 proxy server  
  8. # processname: nginx  
  9. # config:      /usr/local/nginx/conf/nginx.conf  
  10. # pidfile:     /usr/local/nginx/logs/nginx.pid  
  11.   
  12. # Source function library.  
  13. . /etc/rc.d/init.d/functions  
  14.   
  15. # Source networking configuration.  
  16. . /etc/sysconfig/network  
  17.   
  18. # Check that networking is up.  
  19. "$NETWORKING" = "no" ] && exit 0  
  20.   
  21. nginx="/opt/nginx/sbin/nginx"  
  22. prog=$(basename $nginx)  
  23.   
  24. NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"  
  25.   
  26. lockfile=/var/lock/subsys/nginx  
  27.   
  28. start() {  
  29.     [ -x $nginx ] || exit 5  
  30.     [ -f $NGINX_CONF_FILE ] || exit 6  
  31.     echo -n $"Starting $prog: "  
  32.     daemon $nginx -c $NGINX_CONF_FILE  
  33.     retval=$?  
  34.     echo  
  35.     [ $retval -eq 0 ] && touch $lockfile  
  36.     return $retval  
  37. }  
  38.   
  39. stop() {  
  40.     echo -n $"Stopping $prog: "  
  41.     killproc $prog -QUIT  
  42.     retval=$?  
  43.     echo  
  44.     [ $retval -eq 0 ] && rm -f $lockfile  
  45.     return $retval  
  46. }  
  47.   
  48. restart() {  
  49.     configtest || return $?  
  50.     stop  
  51.     start  
  52. }  
  53.   
  54. reload() {  
  55.     configtest || return $?  
  56.     echo -n $"Reloading $prog: "  
  57.     killproc $nginx -HUP  
  58.     RETVAL=$?  
  59.     echo  
  60. }  
  61.   
  62. force_reload() {  
  63.     restart  
  64. }  
  65.   
  66. configtest() {  
  67.   $nginx -t -c $NGINX_CONF_FILE  
  68. }  
  69.   
  70. rh_status() {  
  71.     status $prog  
  72. }  
  73.   
  74. rh_status_q() {  
  75.     rh_status >/dev/null 2>&1  
  76. }  
  77.   
  78. case "$1" in  
  79.     start)  
  80.         rh_status_q && exit 0  
  81.         $1  
  82.         ;;  
  83.     stop)  
  84.         rh_status_q || exit 0  
  85.         $1  
  86.         ;;  
  87.     restart|configtest)  
  88.         $1  
  89.         ;;  
  90.     reload)  
  91.         rh_status_q || exit 7  
  92.         $1  
  93.         ;;  
  94.     force-reload)  
  95.         force_reload  
  96.         ;;  
  97.     status)  
  98.         rh_status  
  99.         ;;  
  100.     condrestart|try-restart)  
  101.         rh_status_q || exit 0  
  102.             ;;  
  103.     *)  
  104.         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"  
  105.         exit 2  
  106. esac  


 

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

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

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

[cpp]  view plain copy
  1. #!/bin/sh  
  2. #  
  3. # Startup script for Spawn-fcgi  
  4. # chkconfig: - 85 15  
  5. # description: Start script for the php-fcgi  
  6. # processname: php-fcgi  
  7.   
  8. FCGI_DAEMON="/opt/spawn-fcgi/bin/spawn-fcgi"  
  9. FCGI_PROGRAM="/opt/php/bin/php-cgi"  
  10. FCGI_SOCKET="/tmp/spawn-fcgi.sock"  
  11. FCGI_PIDFILE="/var/run/spawn-fcgi.pid"  
  12. PHP_FCGI_CHILDREN=4  
  13. PHP_FCGI_MAX_REQUESTS=1000  
  14.   
  15. export PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS  
  16.   
  17. RETVAL=0  
  18. prog="spawn-fcgi"  
  19.   
  20. # Source function library.  
  21. . /etc/init.d/functions  
  22.   
  23. # Source networking configuration.  
  24. . /etc/sysconfig/network  
  25.   
  26. # Check that networking is up.  
  27. [ ${NETWORKING} = "no" ] && exit 0  
  28.   
  29. start() {  
  30.         echo -n $"Starting $prog: "  
  31.         daemon $FCGI_DAEMON -a 127.0.0.1 -p 9000 -u www -g www -f $FCGI_PROGRAM -C $PHP_FCGI_CHILDREN -P $FCGI_PIDFILE  
  32.         RETVAL=$?  
  33.         echo  
  34.         [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog  
  35.         return $RETVAL  
  36. }  
  37.   
  38. stop() {  
  39.         echo -n $"Stopping $prog: "  
  40.         rm -f $FCGI_PIDFILE $FCGI_SOCKET  
  41.         killproc $FCGI_PROGRAM  
  42.         RETVAL=$?  
  43.         echo  
  44.         [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog  
  45.         return $RETVAL  
  46. }  
  47.   
  48. case "$1" in  
  49.         start)  
  50.                 start  
  51.                 ;;  
  52.         stop)  
  53.                 stop  
  54.                 ;;  
  55.         restart)  
  56.                 stop  
  57.                 start  
  58.                 ;;  
  59.         condrestart)  
  60.                 if [ -f /var/lock/subsys/$prog ]; then  
  61.                         stop  
  62.                         start  
  63.                 fi  
  64.                 ;;  
  65.         status)  
  66.                 status $lighttpd  
  67.                 RETVAL=$?  
  68.                 ;;  
  69.         *)  
  70.                 echo $"Usage: $0 {start|stop|restart|condrestart|status}"  
  71.                 RETVAL=1  
  72. esac  
  73.   
  74. exit $RETVAL  


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

[cpp]  view plain copy
  1. > chkconfig --add php-fcgi  
  2. > chkconfig --level 345 php-fcgi on  


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

[cpp]  view plain copy
  1. > service spawn-fcgi stop  
  2. > service spawn-fcgi start  
  3. > service spawn-fcgi restart  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值