Project

General

Profile

Actions

HowToSetupFastCgiIndividualPermissionsInitScript » History » Revision 1

Revision 1/3 | Next »
Anonymous, 2007-05-13 12:20
initial creation


I hope somebody might also find this useful as a init script for several fcgi php daemons with individual user permissions as described [http://trac.lighttpd.net/trac/wiki/HowToSetupFastCgiIndividualPermissions here]

{{{
#! /bin/sh
  1. BEGIN INIT INFO
  1. Provides: FastCGI servers for PHP
  2. Required-Start: networking
  3. Required-Stop: networking
  4. Default-Start: 2 3 4 5
  5. Default-Stop: S 0 1 6
  6. Short-Description: Start PHP FastCGI servers.
  7. Description: PHP can be started with lighttpd's spawn-fcgi binary to
  8. get individual user permisions. This must be done
  9. for each normal user which wants to have PHP support.
    1. END INIT INFO #
  10. Author: Jannis Leidel
  11. <jannis AT leidel.info>. #
  12. Version: @(#)php-fcgi 0.1 12-May-2007 jannis AT leidel.info #
  1. List of user which need own PHP-Fcgi processes
  2. e.g. FCGI_USER_LIST="user1 user2 user3"
    FCGI_USER_LIST=""
  1. Set the socket and pid directory and make sure it exists
    RUNFILES_PATH=/var/run/php-fcgi
    mkdir -p $RUNFILES_PATH

FCGI_PROGRAM="/usr/bin/php-cgi"
FCGI_WEB_SERVER_ADDRS="127.0.0.1"
PHP_FCGI_CHILDREN=2
PHP_FCGI_MAX_REQUESTS=1000

ALLOWED_ENV="PATH USER"
  1. DO NOT CHANGE ANYTHING AFTER THIS LINE!

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="PHP FastCGI servers"

  1. Function that starts all php daemons.
    d_start() {
    export PHP_FCGI_MAX_REQUESTS
    export FCGI_WEB_SERVER_ADDRS
    ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
    E=
    for i in $ALLOWED_ENV; do
    E="$E $i=${!i}"
    done

    for FCGI_USER in $FCGI_USER_LIST
    do
    echo n " $FCGI_USER"
    if [ -f $RUNFILES_PATH/$FCGI_USER.pid ]; then
    echo -n " already running"
    else
    start-stop-daemon --start --quiet --pidfile $RUNFILES_PATH/$FCGI_USER.pid \
    --chuid $FCGI_USER --exec /usr/bin/env -
    spawn-fcgi \
    -s $RUNFILES_PATH/$FCGI_USER.sock -f $FCGI_PROGRAM \
    -u $FCGI_USER -g $FCGI_USER -C $PHP_FCGI_CHILDREN \
    -P $RUNFILES_PATH/$FCGI_USER.pid 2>/dev/null

    chmod 400 $RUNFILES_PATH/$FCGI_USER.pid
    chmod 777 $RUNFILES_PATH/$FCGI_USER.sock
    fi
    done
    }
  1. Function that stops all php daemons.
    d_stop() {
    for FCGI_USER in $FCGI_USER_LIST
    do
    echo -n " $FCGI_USER"
    start-stop-daemon --stop --quiet --pidfile $RUNFILES_PATH/$FCGI_USER.pid \ || echo -n " not running"
    if [ -f $RUNFILES_PATH/$FCGI_USER.pid ]; then
    rm $RUNFILES_PATH/$FCGI_USER.pid
    fi
    done
    }

ACTION="$1"
case "$ACTION" in
start)
echo -n "Starting $DESC: "
d_start
echo "."
;;

stop)
echo -n "Stopping $DESC: "
d_stop
echo "."
;;
restart|force-reload)
echo -n "Restarting $DESC: "
d_stop
sleep 2
d_start
echo "."
;;
*)
echo "Usage: $NAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac

exit 0
}}}

Updated by Anonymous almost 17 years ago · 1 revisions