xref: /PHP-5.3/sapi/fpm/init.d.php-fpm.in (revision bb02fd57)
1#! /bin/sh
2
3### BEGIN INIT INFO
4# Provides:          php-fpm
5# Required-Start:    $remote_fs $network
6# Required-Stop:     $remote_fs $network
7# Default-Start:     2 3 4 5
8# Default-Stop:      0 1 6
9# Short-Description: starts php-fpm
10# Description:       starts the PHP FastCGI Process Manager daemon
11### END INIT INFO
12
13prefix=@prefix@
14exec_prefix=@exec_prefix@
15
16php_fpm_BIN=@sbindir@/php-fpm
17php_fpm_CONF=@sysconfdir@/php-fpm.conf
18php_fpm_PID=@localstatedir@/run/php-fpm.pid
19
20
21php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
22
23
24wait_for_pid () {
25	try=0
26
27	while test $try -lt 35 ; do
28
29		case "$1" in
30			'created')
31			if [ -f "$2" ] ; then
32				try=''
33				break
34			fi
35			;;
36
37			'removed')
38			if [ ! -f "$2" ] ; then
39				try=''
40				break
41			fi
42			;;
43		esac
44
45		echo -n .
46		try=`expr $try + 1`
47		sleep 1
48
49	done
50
51}
52
53case "$1" in
54	start)
55		echo -n "Starting php-fpm "
56
57		$php_fpm_BIN --daemonize $php_opts
58
59		if [ "$?" != 0 ] ; then
60			echo " failed"
61			exit 1
62		fi
63
64		wait_for_pid created $php_fpm_PID
65
66		if [ -n "$try" ] ; then
67			echo " failed"
68			exit 1
69		else
70			echo " done"
71		fi
72	;;
73
74	stop)
75		echo -n "Gracefully shutting down php-fpm "
76
77		if [ ! -r $php_fpm_PID ] ; then
78			echo "warning, no pid file found - php-fpm is not running ?"
79			exit 1
80		fi
81
82		kill -QUIT `cat $php_fpm_PID`
83
84		wait_for_pid removed $php_fpm_PID
85
86		if [ -n "$try" ] ; then
87			echo " failed. Use force-quit"
88			exit 1
89		else
90			echo " done"
91		fi
92	;;
93
94	force-quit)
95		echo -n "Terminating php-fpm "
96
97		if [ ! -r $php_fpm_PID ] ; then
98			echo "warning, no pid file found - php-fpm is not running ?"
99			exit 1
100		fi
101
102		kill -TERM `cat $php_fpm_PID`
103
104		wait_for_pid removed $php_fpm_PID
105
106		if [ -n "$try" ] ; then
107			echo " failed"
108			exit 1
109		else
110			echo " done"
111		fi
112	;;
113
114	restart)
115		$0 stop
116		$0 start
117	;;
118
119	reload)
120
121		echo -n "Reload service php-fpm "
122
123		if [ ! -r $php_fpm_PID ] ; then
124			echo "warning, no pid file found - php-fpm is not running ?"
125			exit 1
126		fi
127
128		kill -USR2 `cat $php_fpm_PID`
129
130		echo " done"
131	;;
132
133	*)
134		echo "Usage: $0 {start|stop|force-quit|restart|reload}"
135		exit 1
136	;;
137
138esac
139