]> git.pld-linux.org Git - packages/php.git/blobdiff - php-fpm.init
use browscap package for browscap.ini data
[packages/php.git] / php-fpm.init
old mode 100644 (file)
new mode 100755 (executable)
index bd2a115..381be8d
-#! /bin/sh
-
-php_fpm_BIN=/usr/bin/php-cgi
-php_fpm_CONF=/etc/php/fpm.conf
-php_fpm_PID=/var/run/php/fpm.pid
-
-
-php_opts="--fpm-config $php_fpm_CONF"
-
-
-wait_for_pid () {
-       try=0
-
-       while test $try -lt 35 ; do
-
-               case "$1" in
-                       'created')
-                       if [ -f "$2" ] ; then
-                               try=''
-                               break
-                       fi
-                       ;;
-
-                       'removed')
-                       if [ ! -f "$2" ] ; then
-                               try=''
-                               break
-                       fi
-                       ;;
-               esac
-
-               echo -n .
-               try=`expr $try + 1`
-               sleep 1
-
-       done
-
+#!/bin/sh
+#
+# @processname@        PHP FastCGI Process Manager
+#
+# chkconfig:   345 80 30
+#
+# description: PHP FastCGI Process Manager
+#
+# processname: @processname@
+# config:      /etc/php/php-fpm.conf
+# pidfile:     /var/run/@processname@.pid
+#
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+# Get network config
+. /etc/sysconfig/network
+
+configfile=/etc/php/php-fpm.conf
+lockfile=/var/lock/subsys/@processname@
+pidfile=$(sed -ne  's,^pid\s*=\s*\(.*\),\1,p' $configfile)
+pidfile=${pidfile:-/var/run/@processname@.pid}
+
+# configtest itself
+# must return non-zero if check failed
+# output is discarded if checkconfig is ran without details
+configtest() {
+       /usr/sbin/@processname@ --fpm-config $configfile -t
+       return $?
 }
 
-case "$1" in
-       start)
-               echo -n "Starting php_fpm "
-
-               $php_fpm_BIN --fpm $php_opts
-
-               if [ "$?" != 0 ] ; then
-                       echo " failed"
-                       exit 1
-               fi
-
-               wait_for_pid created $php_fpm_PID
-
-               if [ -n "$try" ] ; then
-                       echo " failed"
-                       exit 1
+# wrapper for configtest
+checkconfig() {
+       local details=${1:-0}
+
+       if [ $details = 1 ]; then
+               # run config test and display report (status action)
+               show "Checking %s configuration" "PHP FastCGI Process Manager"; busy
+               local out
+               out=$(configtest 2>&1)
+               RETVAL=$?
+               if [ $RETVAL = 0 ]; then
+                       ok
                else
-                       echo " done"
+                       fail
                fi
-       ;;
-
-       stop)
-               echo -n "Shutting down php_fpm "
-
-               if [ ! -r $php_fpm_PID ] ; then
-                       echo "warning, no pid file found - php-fpm is not running ?"
-                       exit 1
+               [ "$out" ] && echo >&2 "$out"
+       else
+               # run config test and abort with nice message if failed
+               # (for actions checking status before action).
+               configtest >/dev/null 2>&1
+               RETVAL=$?
+               if [ $RETVAL != 0 ]; then
+                       show "Checking %s configuration" "PHP FastCGI Process Manager"; fail
+                       nls 'Configuration test failed. See details with %s "checkconfig"' $0
+                       exit $RETVAL
                fi
+       fi
+}
 
-               kill -TERM `cat $php_fpm_PID`
-
-               wait_for_pid removed $php_fpm_PID
-
-               if [ -n "$try" ] ; then
-                       echo " failed"
-                       exit 1
-               else
-                       echo " done"
-               fi
-       ;;
+start() {
+       # Check if the service is already running?
+       if [ -f $lockfile ]; then
+               msg_already_running "PHP FastCGI Process Manager (@processname@)"
+               return
+       fi
+
+       checkconfig
+       msg_starting "PHP FastCGI Process Manager (@processname@)"
+       daemon --redirfds --pidfile $pidfile /usr/sbin/@processname@ --fpm-config $configfile
+       RETVAL=$?
+       [ $RETVAL -eq 0 ] && touch $lockfile
+}
 
-       quit)
-               echo -n "Gracefully shutting down php_fpm "
+stop() {
+       if [ ! -f $lockfile ]; then
+               msg_not_running "PHP FastCGI Process Manager (@processname@)"
+               return
+       fi
+
+       # Stop daemons.
+       msg_stopping "PHP FastCGI Process Manager (@processname@)"
+       # always gracefully shut down @processname@
+       /sbin/start-stop-daemon -q --stop -s QUIT --retry QUIT/600/TERM/10 --pidfile $pidfile
+       [ "$?" -eq 0 ] && ok || fail
+       rm -f $lockfile
+}
 
-               if [ ! -r $php_fpm_PID ] ; then
-                       echo "warning, no pid file found - php-fpm is not running ?"
-                       exit 1
-               fi
+reload() {
+       local sig=${1:-HUP}
+       local retnr=${2:-7}
+       if [ ! -f $lockfile ]; then
+               msg_not_running "PHP FastCGI Process Manager (@processname@)"
+               RETVAL=$retnr
+               return
+       fi
+
+       checkconfig
+       msg_reloading "PHP FastCGI Process Manager (@processname@)"
+       killproc --pidfile $pidfile @processname@ -$sig
+       RETVAL=$?
+}
 
-               kill -QUIT `cat $php_fpm_PID`
+condrestart() {
+       if [ ! -f $lockfile ]; then
+               msg_not_running "PHP FastCGI Process Manager (@processname@)"
+               RETVAL=$1
+               return
+       fi
 
-               wait_for_pid removed $php_fpm_PID
+       checkconfig
+       stop
+       start
+}
 
-               if [ -n "$try" ] ; then
-                       echo " failed"
-                       exit 1
-               else
-                       echo " done"
-               fi
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+       start
        ;;
-
-       restart)
-               $0 stop
-               $0 start
+  stop|quit)
+       stop
        ;;
-
-       reload)
-
-               echo -n "Reload service php-fpm "
-
-               if [ ! -r $php_fpm_PID ] ; then
-                       echo "warning, no pid file found - php-fpm is not running ?"
-                       exit 1
-               fi
-
-               kill -USR2 `cat $php_fpm_PID`
-
-               echo " done"
+  restart)
+       stop
+       start
        ;;
-
-       logrotate)
-
-               echo -n "Re-opening php-fpm log file "
-
-               if [ ! -r $php_fpm_PID ] ; then
-                       echo "warning, no pid file found - php-fpm is not running ?"
-                       exit 1
-               fi
-
-               kill -USR1 `cat $php_fpm_PID`
-
-               echo " done"
+  try-restart)
+       condrestart 0
        ;;
-
-       *)
-               echo "Usage: $0 {start|stop|quit|restart|reload|logrotate}"
-               exit 1
+  reload|force-reload)
+       reload USR2 7
+       ;;
+  checkconfig|configtest)
+       checkconfig 1
+       ;;
+  flush-logs|logrotate)
+       reload USR1 0
+       ;;
+  status)
+       status  --pidfile $pidfile @processname@
+       RETVAL=$?
+       ;;
+  *)
+       msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|flush-logs|checkconfig|status}"
+       exit 3
        ;;
-
 esac
+
+exit $RETVAL
This page took 0.036949 seconds and 4 git commands to generate.