Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

how can i restart spawn-fcgi on nginx server?

share|improve this question

Run it with option -P to store the PID in some temp file. For example:

/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -P /var/run/fcgi.pid 

Then you can kill it by this pid:

kill -9 `cat /var/run/fcgi.pid`
share|improve this answer
    
And make sure that PID file is writable by spawned process (if you're using -u/-g options) or it will be empty – sendmoreinfo Aug 12 '12 at 13:22

How was the process for spawn-fcgi started, was it by a command line (manually) or using a rc-script. In either case you can kill the process by first finding the PID

Use the command ps aux | grep spawn-fcgi to locate the process and the command kill -9 PID

I recommend slashdot's recommendation of using the rc-script to start and end your spawn-fcgi process.

share|improve this answer

Update: This answer randomly failed on me (I'm not sure why) but I'm leaving this here because it might help someone.

killall -9 -w php-cgi

The "-w" waits. Because if you try to (re)start spawn-fcgi too soon (without a delay) spawn-fcgi always gave me error, something like "...already in use." (I don't remember the exact error, sorry.) However, "-w" doesn't work 100% of the time if you plan to put this in cron. After months of random php failures I decided to switch to php-fpm, which has its own unique problems--proceed with caution.

share|improve this answer

I actually prefer to do this kind of process management by using supervisor: http://supervisord.org/

Supervisor will "hang on to your processes": it will restart as necessary, manage the stdout/stderr logging and give you an explicit command for managing the processes without having to mess with PID files etc.

share|improve this answer

Try this:

This should be what you are looking for, current version here

#!/bin/sh
# /etc/init.d/fastcgi-php
#
# System-V like init script for fastcgi-php.
#
### BEGIN INIT INFO
# Provides:          fastcgi-php
# Required-Start:    $local_fs $network $syslog
# Required-Stop:     $local_fs $network $syslog
# Should-Start:      nginx
# Should-Stop:       
# X-Start-Before:    
# X-Stop-After:      
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Fast CGI PHP gateway for Nginx WWW server
# Description:       Script used to spawn a number of php5-cgi processes, 
#                    which are accessed by nginx www server
### END INIT INFO

## Importing generic functions for LSB compliance
. /lib/lsb/init-functions

## Define path which should be searched by the script
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

## Debug variable could be set to 1 or above, for more detailed output
DEBUG="0"
FCGIPHP_BIN_PATH="/usr/bin/php5-cgi"
FCGIPHP_USER="www-data"
FCGIPHP_GROUP="www-data"
FCGIPHP_CHILDREN="6"
FCGIPHP_MAX_REQUEST="1000"
FCGIPHP_SERVER_ADDR="127.0.0.1"
FCGIPHP_SOCKET="/tmp/php-fastcgi.sock"
PIDFILE="/var/run/php5-fastcgi.pid"
SPAWN_FCGI="/usr/bin/spawn-fcgi"
FCGIPHP_ENV="SHELL PATH USER"

# Primary command used to create spawned processes
# based on the variabled defined above
COMMAND_ARGS="${SPAWN_FCGI} -C ${FCGIPHP_CHILDREN} -s ${FCGIPHP_SOCKET} -f ${FCGIPHP_BIN_PATH} -u ${FCGIPHP_USER} -g ${FCGIPHP_GROUP} -P ${PIDFILE}"

export FCGIPHP_MAX_REQUEST
export FCGIPHP_SERVER_ADDR
ALLOWED_ENV="$FCGIPHP_ENV FCGIPHP_MAX_REQUEST FCGIPHP_SERVER_ADDR"
E=""
for i in $ALLOWED_ENV; do
    eval "x=\$$i"
    E="$E $i=$x"
done

start(){
    echo "[INFO] ... STARTING PHP-FCGI ..."
    if [ -f "${PIDFILE}" ]; then
            echo "[WARN] PHP-FCGI is running already. PID file ${PIDFILE} exists."
            RETVAL=1
        elif [ -n "$(pgrep $(basename ${FCGIPHP_BIN_PATH}))" ]; then
            echo "[WARN] PHP-FCGI is running already. PID file is missing!"
        else
            start_daemon ${COMMAND_ARGS}
            RETVAL=$?
    fi

    # echo $COMMAND_ARGS
    # env - $E $COMMAND_ARGS
}

stop(){
    echo "[INFO] ... STOPPING PHP-FCGI ..." 

    if [ -f "${PIDFILE}" ]; then
            killproc -p "${PIDFILE}"
            rm -f "${PIDFILE}"
            rm -f "${FCGIPHP_SOCKET}"
            RETVAL=$?
        elif [ -n "$(pgrep $(basename ${FCGIPHP_BIN_PATH}))" ]; then
            printf "%s\n" "[WARN] PHP-FCGI is not running, or" "[WARN] PID file ${PIDFILE} may have been removed."
            ## echo "[INFO] Removing $(basename ${FCGIPHP_BIN_PATH})"
            killall $(basename $FCGIPHP_BIN_PATH)
            rm -f "${FCGIPHP_SOCKET}"
            RETVAL=$?
        else
            echo "PHP-FCGI is not running."
            RETVAL=1
    fi
}

#Main################
case "$1" in
    'start')
            [ "${DEBUG}" -ge 1 ] && set -x
            log_daemon_msg "Starting Service" "fastcgi-php"
            start
            ;;

    'stop')
            [ "${DEBUG}" -ge 1 ] && set -x
            log_daemon_msg "Stopping Service" "fastcgi-php"
            stop
            ;;

    'status')
            status_of_proc -p "${PIDFILE}" "${FCGIPHP_BIN_PATH}" fastcgi-php
            exit $?
            ;;

    reload|force-reload)  
            log_warning_msg "Online reload not supported"  
            ;;

    'restart')
            log_daemon_msg "Restarting Service" "fastcgi-php"
            stop
            sleep 2
            start
            ;;

    *)
            echo "usage: $0 {start|stop|reload|force-reload|restart}"
            ;;

esac

exit "${RETVAL:-1}"
share|improve this answer
    
While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review – Jakuje Mar 9 at 17:35

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.