#!/sbin/runscript # Copyright 1999-2006 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: $ FILENAME=$(basename "$1") PROGNAME=${FILENAME/fcgi./} SPAWNFCGI=/usr/bin/spawn-fcgi PIDPATH=/var/run/spawn-fcgi PIDFILE=${PIDPATH}/${PROGNAME} depend() { need net } start() { if [[ "${FILENAME}" == "spawn-fcgi" ]]; then eerror "You are not supposed to run this script directly. Create a symlink" eerror "for the FastCGI application you want to run as well as a copy of the" eerror "configuration file and modify it appropriately like so..." eerror eerror " ln -s spawn-fcgi /etc/init.d/fcgi.trac" eerror " cp /etc/conf.d/spawn-fcgi /etc/conf.d/fcgi.trac" eerror " $(basename "${EDITOR}") /etc/conf.d/fcgi.trac" eerror eerror "The new name must start with \"fcgi.\" or it won't work." return 1 fi local X E PHP_FCGI_CHILDREN_OPTION USER_OPTION GROUP_OPTION SOCKET_OPTION PORT_OPTION RETVAL if [[ -z "${FCGI_WEB_SERVER_ADDRS}" ]]; then FCGI_WEB_SERVER_ADDRS=127.0.0.1 fi if [[ -n "${PHP_FCGI_CHILDREN}" ]]; then PHP_FCGI_CHILDREN_OPTION="-C ${PHP_FCGI_CHILDREN}" fi if [[ -z "${FCGI_CHILDREN}" ]]; then FCGI_CHILDREN=1 fi if [[ -n "${FCGI_USER}" ]] && [[ "${FCGI_USER}" != "root" ]]; then USER_OPTION="-u ${FCGI_USER}" fi if [[ -n "${FCGI_GROUP}" ]] && [[ "${FCGI_GROUP}" != "root" ]]; then GROUP_OPTION="-g ${FCGI_GROUP}" fi ALLOWED_ENV="$ALLOWED_ENV USER GROUPS PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS RAILS_ENV TRAC_ENV_PARENT_DIR TRAC_ENV" unset E for i in ${ALLOWED_ENV}; do [[ -n "${!i}" ]] && E="${E} ${i}=${!i}" done # Store all spawn-fcgi PIDs in the same place. install -d "${PIDPATH}" -m 0700 -o root ebegin "Starting FastCGI application ${PROGNAME}" for X in `seq 1 ${FCGI_CHILDREN}`; do [[ -n "${FCGI_SOCKET}" ]] && SOCKET_OPTION="-s ${FCGI_SOCKET}-${X}" [[ -n "${FCGI_PORT}" ]] && PORT_OPTION="-p $((${FCGI_PORT} + ${X} - 1))" env - ${E} ${SPAWNFCGI} ${SOCKET_OPTION} ${PORT_OPTION} -f ${FCGI_PROGRAM} -P ${PIDFILE}-${X}.pid ${USER_OPTION} ${GROUP_OPTION} ${PHP_FCGI_CHILDREN_OPTION} &> /dev/null RETVAL=$? # Stop on error. Don't want to spawn a mess! [[ "${RETVAL}" != "0" ]] && break done eend ${RETVAL} } stop() { local X RETVAL ebegin "Stopping FastCGI application ${PROGNAME}" kill `for X in ${PIDFILE}-[0-9]*.pid; do cat $X; echo -n ' '; done` &> /dev/null RETVAL=$? eend ${RETVAL} rm -f ${PIDFILE}-[0-9]*.pid return $RETVAL }