fastcgi-php-starter-for-freebsd: fastcgi-php.2.sh

File fastcgi-php.2.sh, 1.6 kB (added by freite, 2 years ago)

fixed a small bug preventing it from working with the `fcgiphp_port´ option

Line 
1#!/bin/sh
2#  FreeBSD rc.d script for fastcgi+php
3#  in rc.conf
4# fcgiphp_enable (bool):        Set it to "YES" to enable fastcgi+php
5#                               Default is "NO".
6# other options see below
7#
8
9. /etc/rc.subr
10
11name="fcgiphp"
12rcvar=`set_rcvar`
13
14load_rc_config $name
15
16: ${fcgiphp_enable="NO"}
17: ${fcgiphp_bin_path="/usr/local/bin/php"}
18: ${fcgiphp_user="www"}
19: ${fcgiphp_group="www"}
20: ${fcgiphp_children="10"}
21: ${fcgiphp_port="8002"}
22: ${fcgiphp_socket="/tmp/php-fastcgi.sock"}
23: ${fcgiphp_env="SHELL PATH USER"}
24: ${fcgiphp_max_requests="500"}
25: ${fcgiphp_addr="localhost"}
26
27
28pidfile=/var/run/fcgiphp/fcgiphp.pid
29procname="${fcgiphp_bin_path}"
30command_args="/usr/local/bin/spawn-fcgi 2> /dev/null -f ${fcgiphp_bin_path} -u ${fcgiphp_user} -g ${fcgiphp_group} -C ${fcgiphp_children} -P ${pidfile}"
31start_precmd=start_precmd
32stop_postcmd=stop_postcmd
33
34start_precmd()
35{
36        PHP_FCGI_MAX_REQUESTS="${fcgiphp_max_requests}"
37        FCGI_WEB_SERVER_ADDRS=$fcgiphp_addr
38        export PHP_FCGI_MAX_REQUESTS
39        export FCGI_WEB_SERVER_ADDRS
40        allowed_env="${fcgiphp_env} PHP_FCGI_MAX_REQUESTS FCGI_WEB_SERVER_ADDRS"
41# copy the allowed environment variables
42        E=""
43        for i in $allowed_env; do
44                eval "x=\$$i"
45                E="$E $i=$x"
46        done
47        command="env - $E"
48
49        if [ -n "${fcgiphp_socket}" ]; then
50                command_args="${command_args} -s ${fcgiphp_socket}"
51        elif [ -n "${fcgiphp_port}" ]; then
52                command_args="${command_args} -p ${fcgiphp_port}"
53        else
54                echo "socket or port must be specified!"
55                exit
56        fi
57}
58
59stop_postcmd()
60{
61        rm -f ${pidfile}
62#       eval "ipcs | awk '{ if (\$5 == \"${fcgiphp_user}\") print \"ipcrm -s \"\$2}' | /bin/sh"
63}
64
65run_rc_command "$1"