Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 118 lines (97 sloc) 3.9 KB
#!/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