#! /Bin/sh ### BEGIN INIT INFO # Provides: php-fpm # Required-Start: $ remote_fs $ network # Required-Stop: $ remote_fs $ network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts php-fpm # Description: starts the PHP FastCGI Process Manager daemon ### END INIT INFO Prefix =/usr/local/php Exec_prefix =$ {prefix} Php_fpm_BIN =$ {exec_prefix}/sbin/php-fpm Php_fpm_CONF =$ {prefix}/etc/php-fpm.conf Php_fpm_PID =$ {prefix}/var/run/php-fpm.pid Php_opts = "-- fpm-config $ php_fpm_CONF -- pid $ php_fpm_PID" 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 } Case "$1" in Start) Echo-n "Starting php-fpm" $ Php_fpm_BIN -- daemonize $ 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 Else Echo "done" Fi ;; Stop) Echo-n "Gracefully shutting down php-fpm" If [! -R $ php_fpm_PID]; then Echo "warning, no pid file found-php-fpm is not running? " Exit 1 Fi Kill-QUIT 'cat $ php_fpm_PID' Wait_for_pid removed $ php_fpm_PID If [-n "$ try"]; then Echo "failed. Use force-quit" Exit 1 Else Echo "done" Fi ;; Force-quit) Echo-n "Terminating php-fpm" If [! -R $ php_fpm_PID]; then Echo "warning, no pid file found-php-fpm is not running? " Exit 1 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 ;; Restart) $0 stop $0 start ;; 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" ;; *) Echo "Usage: $0 {start | stop | force-quit | restart | reload }" Exit 1 ;; Esac |