Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

start script

  • Loading branch information...
commit 7e143544d988186b6c6c083b3b7cddc7ca640de2 1 parent 697a91a
@till authored
Showing with 110 additions and 0 deletions.
  1. +110 −0 php-fcgid/php-fcgid
View
110 php-fcgid/php-fcgid
@@ -0,0 +1,110 @@
+#!/bin/sh
+#
+# Author: Till Klampaeckel <till@php.net>
+#
+# Credits
+#
+# * original script: http://unix.derkeiler.com/Mailing-Lists/FreeBSD/questions/2007-09/msg00468.html
+# * improved: http://till.klampaeckel.de/blog/archives/30-PHP-performance-III-Running-nginx.html
+# * all linux start script fu inspired by CouchDB's start script (by Noah Slater)
+#
+
+SCRIPT_OK=0
+SCRIPT_ERROR=1
+
+DESCRIPTION="php-fcgi super-duper-control thing"
+NAME=php-fgcid
+SCRIPT_NAME=$(basename $0)
+
+WWW_GROUP=www-data
+PHP_CGI=/usr/bin/php-cgi
+
+phpfcgid_users="johndoe jandoe"
+phpfcgid_children="2"
+phpfcgid_tmpdir="/tmp"
+phpfcgid_requests="100"
+
+log_daemon_msg () {
+ echo $@
+}
+
+log_end_msg () {
+ # Dummy function to be replaced by LSB library.
+
+ if test "$1" != "0"; then
+ echo "Error with $DESCRIPTION: $NAME"
+ fi
+ return $1
+}
+
+phpfcgid_start() {
+ echo "Starting $NAME with $phpfcgid_children children (req: $phpfcgid_requests)."
+
+ export PHP_FCGI_CHILDREN=$phpfcgid_children
+ export PHP_FCGI_MAX_REQUESTS=$phpfcgid_requests
+
+ for user in ${phpfcgid_users}; do
+ socketdir="${phpfcgid_tmpdir}/.fastcgi.${user}"
+ mkdir -p ${socketdir}
+ chown ${user}:${WWW_GROUP} ${socketdir}
+ chmod 0750 ${socketdir}
+ su -m ${user} -c "${PHP_CGI} -b ${socketdir}/socket&"
+ done
+}
+
+phpfcgid_stop() {
+ echo "Stopping $NAME."
+ pids=`pgrep php-cgi`
+ pkill php-cgi
+}
+
+phpfcgid_status() {
+ log_daemon_msg "To be implemented: status"
+ log_end_msg $SCRIPT_ERROR
+}
+
+
+parse_script_option_list () {
+
+ case "$1" in
+ start)
+ log_daemon_msg "Starting $DESCRIPTION" $NAME
+ if phpfcgid_start; then
+ log_end_msg $SCRIPT_OK
+ else
+ log_end_msg $SCRIPT_ERROR
+ fi
+ ;;
+ stop)
+ log_daemon_msg "Stopping $DESCRIPTION" $NAME
+ if phpfcgid_stop; then
+ log_end_msg $SCRIPT_OK
+ else
+ log_end_msg $SCRIPT_ERROR
+ fi
+ ;;
+ restart|force-reload)
+ log_daemon_msg "Restarting $DESCRIPTION" $NAME
+ if phpfcgid_stop; then
+ if phpfcgid_start; then
+ log_end_msg $SCRIPT_OK
+ else
+ log_end_msg $SCRIPT_ERROR
+ fi
+ else
+ log_end_msg $SCRIPT_ERROR
+ fi
+ ;;
+ status)
+ phpfcgid_status
+ ;;
+ *)
+ cat << EOF >&2
+Usage: $SCRIPT_NAME {start|stop|restart|force-reload|status}
+EOF
+ exit $SCRIPT_ERROR
+ ;;
+ esac
+}
+
+parse_script_option_list $@
Please sign in to comment.
Something went wrong with that request. Please try again.