-
Notifications
You must be signed in to change notification settings - Fork 1
/
php-fpm.init
152 lines (136 loc) · 3.06 KB
/
php-fpm.init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/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 $?
}
# 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
fail
fi
[ "$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
}
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
}
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
}
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=$?
}
condrestart() {
if [ ! -f $lockfile ]; then
msg_not_running "PHP FastCGI Process Manager (@processname@)"
RETVAL=$1
return
fi
checkconfig
stop
start
}
RETVAL=0
# See how we were called.
case "$1" in
start)
start
;;
stop|quit)
stop
;;
restart)
stop
start
;;
try-restart)
condrestart 0
;;
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