Skip to content

Instantly share code, notes, and snippets.

@iGhost
Created February 3, 2014 11:28
Show Gist options
  • Select an option

  • Save iGhost/8782348 to your computer and use it in GitHub Desktop.

Select an option

Save iGhost/8782348 to your computer and use it in GitHub Desktop.

Revisions

  1. iGhost created this gist Feb 3, 2014.
    54 changes: 54 additions & 0 deletions spawn-fcgi starter
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #!/bin/bash

    lockfile=/tmp/fastcgi_locked

    start() {
    for user in `ls /var/cpanel/users`; do
    if [ -e /home/${user}/public_html/php-fcgi.sock ]; then
    echo "Socket exist, exiting!"
    exit 0
    fi
    /usr/bin/spawn-fcgi -u ${user} -g ${user} -s /home/${user}/public_html/php-fcgi.sock -S -M 0600 -C 16 -F 1 -P /var/run/fcgi-${user}.pid -f "/usr/bin/php-cgi -c /home/${user}/${user}.ini" -U nobody -G nobody
    done
    rm -f $lockfile
    }

    stop() {
    killall -TERM php-cgi && echo "Killed!"
    touch $lockfile
    }

    check() {
    if [ -e $lockfile ]; then
    echo "Lockfile found, exiting!"
    fi
    for user in `ls /var/cpanel/users`; do
    proc=`ps aux | grep php-cgi | grep ${user}`
    if [ ! "${proc}" ]; then
    echo "Oops!"
    /usr/bin/spawn-fcgi -u ${user} -g ${user} -s /home/${user}/public_html/php-fcgi.sock -S -M 0600 -C 16 -F 1 -P /var/run/fcgi-${user}.pid -f "/usr/bin/php-cgi -c /home/${user}/${user}.ini" -U nobody -G nobody
    else
    echo "It's alive!"
    fi
    done
    }

    case "$1" in
    start)
    $1
    ;;
    stop)
    $1
    ;;
    restart)
    stop
    start
    ;;
    check)
    $1
    ;;
    *)
    echo $"Usage: $0 {start|stop|check|restart}"
    exit 2
    esac
    exit $?