]>
Commit | Line | Data |
---|---|---|
c0240cb1 | 1 | #!/bin/sh |
2 | # | |
654a0f7f | 3 | # @processname@ PHP FastCGI Process Manager |
c0240cb1 | 4 | # |
5 | # chkconfig: 345 80 30 | |
6 | # | |
7 | # description: PHP FastCGI Process Manager | |
8 | # | |
654a0f7f | 9 | # processname: @processname@ |
c0240cb1 | 10 | # config: /etc/php/php-fpm.conf |
d936e544 | 11 | # pidfile: /var/run/@processname@.pid |
c0240cb1 | 12 | # |
c0240cb1 | 13 | |
14 | # Source function library | |
15 | . /etc/rc.d/init.d/functions | |
16 | ||
17 | # Get network config | |
18 | . /etc/sysconfig/network | |
19 | ||
ee5a2c46 | 20 | configfile=/etc/php/php-fpm.conf |
654a0f7f | 21 | lockfile=/var/lock/subsys/@processname@ |
ee5a2c46 | 22 | pidfile=$(sed -ne 's,^pid\s*=\s*\(.*\),\1,p' $configfile) |
d936e544 | 23 | pidfile=${pidfile:-/var/run/@processname@.pid} |
c0240cb1 | 24 | |
792bf68d ER |
25 | # configtest itself |
26 | # must return non-zero if check failed | |
27 | # output is discarded if checkconfig is ran without details | |
28 | configtest() { | |
29 | /usr/sbin/@processname@ --fpm-config $configfile -t | |
30 | return $? | |
31 | } | |
32 | ||
33 | # wrapper for configtest | |
34 | checkconfig() { | |
35 | local details=${1:-0} | |
36 | ||
37 | if [ $details = 1 ]; then | |
38 | # run config test and display report (status action) | |
39 | show "Checking %s configuration" "PHP FastCGI Process Manager"; busy | |
40 | local out | |
41 | out=$(configtest 2>&1) | |
42 | RETVAL=$? | |
43 | if [ $RETVAL = 0 ]; then | |
44 | ok | |
45 | else | |
46 | fail | |
47 | fi | |
48 | [ "$out" ] && echo >&2 "$out" | |
49 | else | |
50 | # run config test and abort with nice message if failed | |
51 | # (for actions checking status before action). | |
52 | configtest >/dev/null 2>&1 | |
53 | RETVAL=$? | |
54 | if [ $RETVAL != 0 ]; then | |
55 | show "Checking %s configuration" "PHP FastCGI Process Manager"; fail | |
56 | nls 'Configuration test failed. See details with %s "checkconfig"' $0 | |
57 | exit $RETVAL | |
58 | fi | |
59 | fi | |
60 | } | |
61 | ||
c0240cb1 | 62 | start() { |
63 | # Check if the service is already running? | |
873fb29e | 64 | if [ -f $lockfile ]; then |
654a0f7f | 65 | msg_already_running "PHP FastCGI Process Manager (@processname@)" |
873fb29e | 66 | return |
c0240cb1 | 67 | fi |
873fb29e | 68 | |
792bf68d | 69 | checkconfig |
654a0f7f | 70 | msg_starting "PHP FastCGI Process Manager (@processname@)" |
ba07e9b4 | 71 | daemon --redirfds --pidfile $pidfile /usr/sbin/@processname@ --fpm-config $configfile |
873fb29e ER |
72 | RETVAL=$? |
73 | [ $RETVAL -eq 0 ] && touch $lockfile | |
c0240cb1 | 74 | } |
75 | ||
76 | stop() { | |
873fb29e | 77 | if [ ! -f $lockfile ]; then |
654a0f7f | 78 | msg_not_running "PHP FastCGI Process Manager (@processname@)" |
873fb29e | 79 | return |
c0240cb1 | 80 | fi |
873fb29e ER |
81 | |
82 | # Stop daemons. | |
654a0f7f ER |
83 | msg_stopping "PHP FastCGI Process Manager (@processname@)" |
84 | # always gracefully shut down @processname@ | |
873fb29e ER |
85 | /sbin/start-stop-daemon -q --stop -s QUIT --retry QUIT/600/TERM/10 --pidfile $pidfile |
86 | [ "$?" -eq 0 ] && ok || fail | |
87 | rm -f $lockfile | |
c0240cb1 | 88 | } |
89 | ||
90 | reload() { | |
91 | local sig=${1:-HUP} | |
92 | local retnr=${2:-7} | |
873fb29e | 93 | if [ ! -f $lockfile ]; then |
654a0f7f | 94 | msg_not_running "PHP FastCGI Process Manager (@processname@)" |
c0240cb1 | 95 | RETVAL=$retnr |
873fb29e | 96 | return |
c0240cb1 | 97 | fi |
873fb29e | 98 | |
792bf68d | 99 | checkconfig |
654a0f7f ER |
100 | msg_reloading "PHP FastCGI Process Manager (@processname@)" |
101 | killproc --pidfile $pidfile @processname@ -$sig | |
873fb29e | 102 | RETVAL=$? |
c0240cb1 | 103 | } |
104 | ||
105 | condrestart() { | |
873fb29e | 106 | if [ ! -f $lockfile ]; then |
654a0f7f | 107 | msg_not_running "PHP FastCGI Process Manager (@processname@)" |
c0240cb1 | 108 | RETVAL=$1 |
873fb29e | 109 | return |
c0240cb1 | 110 | fi |
873fb29e | 111 | |
792bf68d | 112 | checkconfig |
873fb29e ER |
113 | stop |
114 | start | |
c0240cb1 | 115 | } |
116 | ||
117 | RETVAL=0 | |
118 | # See how we were called. | |
119 | case "$1" in | |
120 | start) | |
121 | start | |
122 | ;; | |
123 | stop|quit) | |
124 | stop | |
125 | ;; | |
126 | restart) | |
127 | stop | |
128 | start | |
129 | ;; | |
130 | try-restart) | |
131 | condrestart 0 | |
132 | ;; | |
133 | reload|force-reload) | |
134 | reload USR2 7 | |
135 | ;; | |
792bf68d ER |
136 | checkconfig|configtest) |
137 | checkconfig 1 | |
138 | ;; | |
c0240cb1 | 139 | flush-logs|logrotate) |
140 | reload USR1 0 | |
141 | ;; | |
142 | status) | |
ee5a2c46 | 143 | status --pidfile $pidfile @processname@ |
c0240cb1 | 144 | RETVAL=$? |
145 | ;; | |
146 | *) | |
792bf68d | 147 | msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|flush-logs|checkconfig|status}" |
c0240cb1 | 148 | exit 3 |
149 | ;; | |
150 | esac | |
151 | ||
152 | exit $RETVAL |