Project

General

Profile

Fastcgi-php-starter-for-freebsd » fastcgi-php.2.sh

fixed a small bug preventing it from working with the `fcgiphp_port´ option - Anonymous, 2006-06-14 11:34

 
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

    
11
name="fcgiphp"
12
rcvar=`set_rcvar`
13

    
14
load_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

    
28
pidfile=/var/run/fcgiphp/fcgiphp.pid
29
procname="${fcgiphp_bin_path}"
30
command_args="/usr/local/bin/spawn-fcgi 2> /dev/null -f ${fcgiphp_bin_path} -u ${fcgiphp_user} -g ${fcgiphp_group} -C ${fcgiphp_children} -P ${pidfile}"
31
start_precmd=start_precmd
32
stop_postcmd=stop_postcmd
33

    
34
start_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

    
59
stop_postcmd()
60
{
61
	rm -f ${pidfile}
62
#	eval "ipcs | awk '{ if (\$5 == \"${fcgiphp_user}\") print \"ipcrm -s \"\$2}' | /bin/sh"
63
}
64

    
65
run_rc_command "$1"
66

    
(2-2/2)