Created
August 5, 2010 19:25
-
-
Save dpetzold/510245 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## BEGIN INIT INFO | |
# Provides: FastCGI servers for PHP | |
# Required-Start: networking | |
# Required-Stop: networking | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: S 0 1 6 | |
# Short-Description: Start FastCGI servers with PHP. | |
# Description: Start PHP with spawn-fcgi. For use with nginx and lighttpd. | |
# | |
# | |
### END INIT INFO | |
# | |
# Author: Derrick Petzold | |
# | |
# http://derrickpetzold.com/index.php/2010/07/02/init-script-fastcgi-php-ubuntu/ | |
# | |
RUN_USER=nobody | |
RUN_GROUP=nogroup | |
LISTEN_ADDRESS=127.0.0.1 | |
LISTEN_PORT=53217 | |
SPAWN_FCGI=/opt/lighttpd/bin/spawn-fcgi | |
PHP_CGI=/opt/php5/bin/php-cgi | |
PID_FILE=/var/run/fastcgi-php.pid | |
d_start() { | |
if [ -f $PID_FILE ]; then | |
echo -n " already running" | |
else | |
start-stop-daemon --start -p $PID_FILE \ | |
--exec /usr/bin/env -- $SPAWN_FCGI -f $PHP_CGI \ | |
-u $RUN_USER -g $RUN_GROUP -a $LISTEN_ADDRESS -p $LISTEN_PORT \ | |
-P $PID_FILE | |
fi | |
} | |
d_stop() { | |
start-stop-daemon --stop --quiet --pidfile $PID_FILE \ | |
|| echo -n " not running" | |
if [ -f $PID_FILE ]; then | |
rm $PID_FILE | |
fi | |
} | |
case "$1" in | |
start) | |
echo -n "Starting FastCGI: $0 " | |
d_start | |
echo "." | |
;; | |
stop) | |
echo -n "Stopping FastCGI: $0 " | |
d_stop | |
echo "." | |
;; | |
restart) | |
echo -n "Restarting FastCGI: $0 " | |
d_stop | |
sleep 1 | |
d_start | |
;; | |
*) | |
echo "usage: $0 {start|stop|restart}" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment