-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathphp-cgi
executable file
·117 lines (97 loc) · 3.9 KB
/
php-cgi
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
#!/bin/bash
# php-cgi --- Init script for starting PHP CGI.
# Copyright (C) 2010 António P. P. Almeida <appa@perusio.net>
# Author: António P. P. Almeida <appa@perusio.net>
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# Except as contained in this notice, the name(s) of the above copyright
# holders shall not be used in advertising or otherwise to promote the sale,
# use or other dealings in this Software without prior written authorization.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
### BEGIN INIT INFO
# Provides: php-fcgi
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the php-fcgi process.
# Description: starts php-fcgi using start-stop-daemon
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/php-cgi
NAME=php-cgi
DESC=FastCGI
PIDFILE=/var/run/$NAME.pid
test -x $DAEMON || exit 0
## Whether the php cgi daemon should receive incoming requests using
## UNIX sockets or Internet Sockets. The default is Internet sockets.
## Include php-cgi defaults if available.
if [ -f /etc/default/$NAME ] ; then
. /etc/default/$NAME
else
USE_UNIX=0
fi
## Check to see if the daemon is enabled.
if [ $STARTUP != "1" ]; then
echo "To enable $NAME, edit /etc/default/$NAME and set STARTUP=1"
exit 0
fi
## The user the process will run under.
USER=www-data
GROUP=www-data
## FastCGI specific parameters.
export PHP_FCGI_CHILDREN=${PHP_FCGI_CHILDREN-6}
export PHP_FCGI_MAX_REQUESTS=${PHP_FCGI_MAX_REQUESTS-1000}
## The arguments to pass to the php cgi program.
DAEMON_OPTIONS="- USER=$USER GROUP=$GROUP PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS"
## Using UNIX sockets or not. Set the binding.
if [ $USE_UNIX == "1" ]; then
SOCKET_DIR=/tmp/php-cgi
mkdir -p $SOCKET_DIR
chown $USER:$GROUP $SOCKET_DIR
chmod 700 $SOCKET_DIR
BIND="$SOCKET_DIR/php-cgi.socket"
else
BIND=127.0.0.1:9000
fi
## Get the status of the PHP FastCGI daemon(s).
php_cgi_status () {
pidof $DAEMON 2&>1 >/dev/null && echo " * $NAME is running" || echo " * $NAME is not running"
}
case "$1" in
start)
echo -n " Starting $DESC: "
start-stop-daemon --quiet --start --background --chuid "$USER" --pidfile $PIDFILE --make-pidfile --exec /usr/bin/env -- $DAEMON_OPTIONS $DAEMON -b $BIND
echo "$NAME."
;;
stop)
echo -n " Stopping $DESC: "
killall -q -w -u $USER $DAEMON
echo "$NAME."
;;
restart|force-reload)
echo -n " Restarting $DESC: "
killall -q -w -u $USER $DAEMON
start-stop-daemon --quiet --start --background --chuid "$USER" --pidfile $PIDFILE --make-pidfile --exec /usr/bin/env -- $DAEMON_OPTIONS $DAEMON -b $BIND
echo "$NAME."
;;
status)
php_cgi_status
;;
*)
echo "Usage: $NAME {start|stop|force-reload|restart|status}"
exit 1
;;
esac