Skip to content

Instantly share code, notes, and snippets.

@daisuke0604
Created February 21, 2014 05:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daisuke0604/9129406 to your computer and use it in GitHub Desktop.
Save daisuke0604/9129406 to your computer and use it in GitHub Desktop.
php-fastcgi 起動スクリプト for raspbian
#!/bin/bash
#
# php-fastcgi PHP FastCGI Process Manager
#
# chkconfig: - 84 16
# description: PHP FastCGI Process Manager
# processname: php-cgi
# config: /etc/php.conf
### BEGIN INIT INFO
# Provides: php-fastcgi
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-fastcgi
# Description: Starts PHP FastCGI Process Manager Daemon
### END INIT INFO
BIND=127.0.0.1:9000
USER=www-data
# FASTCGI Server でデフォルト起動するプロセス数を指定します。
# --- ここを0にしてしまうとPHP_FCGI_MAX_REQUESTSで指定した処理数を超えた場合、自動的に php-cgi のプロセスは、全て終了してしまいます。
# --- 通常は、2以上の数値を設定します。
PHP_FCGI_CHILDREN=2
# FASTCGI Server で1プロセスあたりの処理数を指定します。
# --- ここで指定した処理数を超えた場合、自動的に php-cgi のプロセスは、再生されます。
PHP_FCGI_MAX_REQUESTS=1000
PHP_SHELL_NAME="php-fastcgi"
PHP_CGI_PATH=/usr/bin/php-cgi
PHP_CGI_PID=/var/run/php-cgi.pid
ENV_PATH=/usr/bin/env
ENV_EXE="$ENV_PATH -- - USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS"
PHP_CGI_EXE="$PHP_CGI_PATH -b $BIND"
RETVAL=0
. /lib/lsb/init-functions
result_cmd() {
local rc=$1
echo $PHP_SHELL_NAME
return $rc
}
start() {
echo -n "Starting PHP FastCGI: "
RETVAL=1
if [ ! -e $PHP_CGI_PID ] ; then
start-stop-daemon --quiet --start --background --make-pidfile --pidfile $PHP_CGI_PID --chuid "$USER" --exec $ENV_EXE $PHP_CGI_EXE
RETVAL=$?
fi
result_cmd $RETVAL "startup"
}
stop() {
echo -n "Stopping PHP FastCGI: "
RETVAL=1
if [ -e $PHP_CGI_PID ] ; then
start-stop-daemon --stop --pidfile $PHP_CGI_PID
RETVAL=$?
fi
result_cmd $RETVAL "shutdown"
if [ $RETVAL -eq 0 ] ; then
rm -f $PHP_CGI_PID;
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status_of_proc "$PHP_CGI_PATH" "$PHP_SHELL_NAME" && exit 0 || exit $?
;;
*)
echo "Usage: $PHP_SHELL_NAME {start|stop|restart|status}"
exit 1
;;
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment