xref: /PHP-5.4/sapi/fpm/init.d.php-fpm.in (revision ee01af7d)
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	status)
95		if [ ! -r $php_fpm_PID ] ; then
96			echo "php-fpm is stopped"
97			exit 0
98		fi
99
100		PID=`cat $php_fpm_PID`
101		if ps -p $PID | grep -q $PID; then
102			echo "php-fpm (pid $PID) is running..."
103		else
104			echo "php-fpm dead but pid file exists"
105		fi
106	;;
107
108	force-quit)
109		echo -n "Terminating php-fpm "
110
111		if [ ! -r $php_fpm_PID ] ; then
112			echo "warning, no pid file found - php-fpm is not running ?"
113			exit 1
114		fi
115
116		kill -TERM `cat $php_fpm_PID`
117
118		wait_for_pid removed $php_fpm_PID
119
120		if [ -n "$try" ] ; then
121			echo " failed"
122			exit 1
123		else
124			echo " done"
125		fi
126	;;
127
128	restart)
129		$0 stop
130		$0 start
131	;;
132
133	reload)
134
135		echo -n "Reload service php-fpm "
136
137		if [ ! -r $php_fpm_PID ] ; then
138			echo "warning, no pid file found - php-fpm is not running ?"
139			exit 1
140		fi
141
142		kill -USR2 `cat $php_fpm_PID`
143
144		echo " done"
145	;;
146
147	*)
148		echo "Usage: $0 {start|stop|force-quit|restart|reload|status}"
149		exit 1
150	;;
151
152esac
153