aboutsummaryrefslogtreecommitdiff
path: root/www/apache13-modssl/files/apache.in
blob: 95f8bb7fd321084d04242f988977805f5ed82ff8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: apache
# REQUIRE: LOGIN cleanvar
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable apache:
# apache_enable (bool):      Set to "NO" by default.
#                             Set it to "YES" to enable apache
# apache_profiles (str):     Set to "" by default.
#                              Define your profiles here.
# apachelimits_enable (bool):Set to "NO" by default.
#                             Set it to yes to run `limits $limits_args`
#                             just before apache starts.
# apache_flags (str):        Set to "-DSSL" by default.
#                             Extra flags passed to start command.
# apachelimits_args (str):   Default to "-e -C daemon"
#                             Arguments of pre-start limits run.
# apache_http_accept_enable (bool): Set to "NO" by default.
#                             Set to yes to check for accf_http kernel
#                             module on start up and load if not loaded.
# apache_fib (str):	      Set an altered default network view for apache

. /etc/rc.subr

name="apache"
rcvar=`set_rcvar`

start_precmd="apache_prestart"
restart_precmd="apache_checkconfig"
reload_precmd="apache_checkconfig"
reload_cmd="apache_graceful"
graceful_cmd="apache_graceful"
gracefulstop_cmd="apache_gracefulstop"
configtest_cmd="apache_checkconfig"
command="%%PREFIX%%/sbin/httpd"
_pidprefix="/var/run/httpd"
pidfile="${_pidprefix}.pid"
required_files=%%PREFIX%%/etc/apache/httpd.conf

[ -z "$apache_enable" ]       && apache_enable="NO"
[ -z "$apache_profiles" ]     && apache_profiles=""
[ -z "$apache_flags" ]        && apache_flags="-DSSL"
[ -z "$apachelimits_enable" ] && apachelimits_enable="NO"
[ -z "$apachelimits_args" ]   && apachelimits_args="-e -C daemon"
[ -z "$apache_http_accept_enable" ] && apache_http_accept_enable="NO"
[ -z "$apache_fib" ] && apache_fib="NO"

apache_accf() {
	retcode=0
	if checkyesno apache_http_accept_enable
	then
		/sbin/kldstat -v | grep accf_http >/dev/null 2>&1
		retcode=${?}
		if [ ${retcode} -ne 0 ]
		then
			/sbin/kldload accf_http 2> /dev/null
			retcode=${?}
		fi
	else
		apache_flags="${apache_flags} -DNOHTTPACCEPT"
	fi
	[ ${retcode} -ne 0 ] && echo "Unable to load accf_http module"
	return ${retcode}
}

load_rc_config $name

if [ -n "$2" ]; then
	profile="$2"
	if [ "x${apache_profiles}" != "x" ]; then
		pidfile="${_pidprefix}.${profile}.pid"
		eval apache_configfile="\${apache_${profile}_configfile:-}"
		if [ "x${apache_configfile}" = "x" ]; then
			echo "You must define a configuration file (apache_${profile}_configfile)"
			exit 1
		fi
		required_files="${apache_configfile}"
		eval apache_enable="\${apache_${profile}_enable:-${apache_enable}}"
		eval apache_flags="\${apache_${profile}_flags:-${apache_flags}}"
		eval apache_http_accept_enable="\${apache_${profile}_http_accept_enable:-${apache_http_accept_enable}}"
		eval apachelimits_enable="\${apachelimits_${profile}_enable:-${apachelimits_enable}}"
		eval apachelimits_args="\${apachelimits_${profile}_args:-${apachelimits_args}}"
		eval apache_fib="\${apache_${profile}_fib:-${apache_fib}}"
		apache_flags="-f ${apache_configfile} -c \"PidFile ${pidfile}\" ${apache_flags}"
	else
		echo "$0: extra argument ignored"
	fi
else
	if [ "x${apache_profiles}" != "x" -a "x$1" != "x" ]; then
		for profile in ${apache_profiles}; do
			eval _enable="\${apache_${profile}_enable}"
			case "x${_enable:-${apache_enable}}" in
			x|x[Nn][Oo]|x[Nn][Oo][Nn][Ee])
				continue
				;;
			x[Yy][Ee][Ss])
				;;
			*)
				if test -z "$_enable"; then
					_var=apache_enable
				else
					_var=apache_"${profile}"_enable
				fi
				echo "Bad value" \
				    "'${_enable:-${apache_enable}}'" \
				    "for ${_var}. " \
				    "Profile ${profile} skipped."
				continue
				;;
			esac
			echo "===> apache profile: ${profile}"
			%%PREFIX%%/etc/rc.d/apache%%RC_SUBR_SUFFIX%% $1 ${profile}
			retcode="$?"
			if [ "0${retcode}" -ne 0 ]; then
				failed="${profile} (${retcode}) ${failed:-}"
			else
				success="${profile} ${success:-}"
			fi
		done
		exit 0
	fi
fi

if [ "${1}" != "stop" ] ; then \
	apache_accf || apache_flags="${apache_flags} -DNOHTTPACCEPT"
fi

apache_requirepidfile()
{
	if [ ! "0`check_pidfile ${pidfile} ${command}`" -gt 1 ]; then
		echo "${name} not running? (check $pidfile)."
		exit 1
	fi
}

apache_checkconfig()
{
	if test -f %%PREFIX%%/sbin/envvars
	then
		. %%PREFIX%%/sbin/envvars
	fi

	echo "Performing sanity check on apache configuration:"
	eval ${command} ${apache_flags} -t
}

apache_graceful() {
	apache_requirepidfile

	echo "Performing a graceful restart"
	eval ${command} ${apache_flags} -k graceful
}

apache_gracefulstop() {
	apache_requirepidfile

	echo "Performing a graceful stop"
	eval ${command} ${apache_flags} -k graceful-stop
}

apache_precmd() 
{
	apache_checkconfig

	if checkyesno apachelimits_enable
	then
		eval `/usr/bin/limits ${apachelimits_args}` 2>/dev/null
	else
		return 0
        fi

}

apache_checkfib () {
	sysctl net.fibs >/dev/null 2>&1
	ret=$? 
 	[ $ret -gt 0 ] && return 0 
	if [ "x$apache_fib" != "xNO" ]
	then 
		command="setfib -F ${apache_fib} ${command}"
	else
		return	0
	fi
}

apache_prestart() {
	apache_checkfib
	apache_precmd
}

extra_commands="reload graceful gracefulstop configtest"
run_rc_command "$1"
# eof