Skip to content

Instantly share code, notes, and snippets.

@iGhost
Created February 3, 2014 11:28
Show Gist options
  • Save iGhost/8782348 to your computer and use it in GitHub Desktop.
Save iGhost/8782348 to your computer and use it in GitHub Desktop.
#!/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 $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment