Posted By

jturmel on 12/28/09


Tagged

php nginx initd phpcgi php-cgi


Versions (?)

php_cgi init.d


 / Published in: Bash
 

  1. #!/bin/sh
  2. #
  3. # php-cgi - php-fastcgi swaping via spawn-fcgi
  4. #
  5. # chkconfig: - 85 15
  6. # description: Run php-cgi as app server
  7. # processname: php-cgi
  8. # config: /etc/sysconfig/phpfastcgi (defaults RH style)
  9. # pidfile: /var/run/php_cgi.pid
  10. # Note: See how to use this script :
  11. # http://www.cyberciti.biz/faq/rhel-fedora-install-configure-nginx-php5/
  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. spawnfcgi="/usr/bin/spawn-fcgi"
  22. php_cgi="/usr/bin/php-cgi"
  23. prog=$(basename $php_cgi)
  24. server_ip=127.0.0.1
  25. server_port=9000
  26. server_user=nginx
  27. server_group=nginx
  28. server_childs=5
  29. pidfile="/var/run/php_cgi.pid"
  30.  
  31. # do not edit, put changes in /etc/sysconfig/phpfastcgi
  32. [ -f /etc/sysconfig/phpfastcgi ] && . /etc/sysconfig/phpfastcgi
  33.  
  34. start() {
  35. [ -x $php_cgi ] || exit 1
  36. [ -x $spawnfcgi ] || exit 2
  37. echo -n $"Starting $prog: "
  38. daemon $spawnfcgi -a ${server_ip} -p ${server_port} -u ${server_user} -g ${server_group} -P ${pidfile} -C ${server_childs} -f ${php_cgi}
  39. retval=$?
  40. echo
  41. return $retval
  42. }
  43.  
  44. stop() {
  45. echo -n $"Stopping $prog: "
  46. killproc -p ${pidfile} $prog -QUIT
  47. retval=$?
  48. echo
  49. [ -f ${pidfile} ] && /bin/rm -f ${pidfile}
  50. return $retval
  51. }
  52.  
  53. restart(){
  54. stop
  55. sleep 2
  56. start
  57. }
  58.  
  59. rh_status(){
  60. status -p ${pidfile} $prog
  61. }
  62.  
  63. case "$1" in
  64. start)
  65. start;;
  66. stop)
  67. stop;;
  68. restart)
  69. restart;;
  70. status)
  71. rh_status;;
  72. *)
  73. echo $"Usage: $0 {start|stop|restart|status}"
  74. exit 3
  75. esac

Report this snippet  

You need to login to post a comment.