Date: Sun, 1 Jan 2006 15:23:29 +1030 (CST) From: Jarrod Sayers <jarrod@netleader.com.au> To: FreeBSD-gnats-submit@FreeBSD.org Cc: Clement Laforet <clement@FreeBSD.org> Subject: ports/91154: [patch] www/apache22: Add profile support, prevent reload/restart when httpd not running and various tweaks Message-ID: <200601010453.k014rTXX063949@wallace.netleader.com.au> Resent-Message-ID: <200601010500.k0150EhI039536@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 91154 >Category: ports >Synopsis: [patch] www/apache22: Add profile support, prevent reload/restart when httpd not running and various tweaks >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-ports-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Jan 01 05:00:13 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Jarrod Sayers >Release: FreeBSD 4.11-RELEASE-p13 i386 >Organization: >Environment: System: FreeBSD wallace.netleader.com.au 4.11-RELEASE-p13 FreeBSD 4.11-RELEASE-p13 #16: Sat Nov 26 17:10:11 CST 2005 root@wallace.netleader.com.au:/usr/obj/usr/src/sys/WALLACE i386 >Description: Various suggested changes to ports/www/apache22/files/apache.sh, including: - Rearranging and tidy up of apache.sh descriptions, including minor alterations to terminology and formatting to make it a little easier to read. - Add configtest to extra_commands to allow testing of configs. Handy command especially when used in conjunction with profiles as apachectl does not support the overriding of a file to test (must use 'httpd -f ... -t' instead). - Add support for apache22 profiles (inspired by www/apache20). - Add apache22_requirepidfile function to check for running process. - Prevent reload/restart when httpd process not running. Required as script execution with reload/restart without running processes actually starts them, without any additional options (like -DNOHTTPACCEPT or profile info). - Force apache22_checkconfig when start issued (config not currently tested on start's, only used on reload and restart). >How-To-Repeat: >Fix: Diff obtainable from: http://www.netleader.com.au/~jarrod/freebsd/www-apache22-files-apache.sh.diff --- www-apache22-files-apache.sh.diff begins here --- --- ports/www/apache22/files/apache.sh.orig Tue Dec 20 03:31:42 2005 +++ ports/www/apache22/files/apache.sh Sun Jan 1 14:47:13 2006 @@ -10,18 +10,22 @@ # # Add the following lines to /etc/rc.conf to enable apache22: -# apache22_enable (bool): Set to "NO" by default. -# Set it to "YES" to enable apache22 -# apache22limits_enable (bool):Set to "NO" by default. -# Set it to yes to run `limits $limits_args` -# just before apache starts. -# apache22_flags (str): Set to "" by default. -# Extra flags passed to start command. -# apache22limits_args (str): Default to "-e -C daemon" -# Arguments of pre-start limits run. +# apache22_enable (bool): Set to "NO" by default. +# Set it to "YES" to enable apache22. +# apache22_profiles (str): Set to "" by default. +# Define your profiles here. +# apache22_flags (str): Set to "" by default. +# Extra flags passed to start command. # apache22_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. +# Set it to "YES" to check for accf_http kernel +# module on start up and load if required. +# apache22limits_enable (bool): Set to "NO" by default. +# Set it to "YES" to run `limits ${apache22limits_args}` +# just before apache starts. +# apache22limits_args (str): Default to "-e -C daemon". +# Arguments of pre-start limits run. +# + . %%RC_SUBR%% name="apache22" @@ -33,59 +37,108 @@ reload_cmd="apache22_graceful" graceful_cmd="apache22_graceful" gracefulstop_cmd="apache22_gracefulstop" +configtest_cmd="apache22_checkconfig" command="%%PREFIX%%/sbin/httpd" -pidfile="/var/run/httpd.pid" -required_files=%%PREFIX%%/etc/apache22/httpd.conf +_pidprefix="/var/run/httpd" +pidfile="${_pidprefix}.pid" +required_files="%%PREFIX%%/etc/apache22/httpd.conf" + +[ -z "${apache22_enable}" ] && apache22_enable="NO" +[ -z "${apache22_profiles}" ] && apache22_profiles="" +[ -z "${apache22_flags}" ] && apache22_flags="" +[ -z "${apache22_http_accept_enable}" ] && apache22_http_accept_enable="NO" +[ -z "${apache22limits_enable}" ] && apache22limits_enable="NO" +[ -z "${apache22limits_args}" ] && apache22limits_args="-e -C daemon" + +load_rc_config "${name}" + +if [ -n "$2" ]; then + profile="$2" + if [ "x${apache22_profiles}" != "x" ]; then + pidfile="${_pidprefix}.${profile}.pid" + eval apache22_configfile="\${apache22_${profile}_configfile:-}" + if [ "x${apache22_configfile}" = "x" ]; then + echo "You must define a configuration file (apache22_${profile}_configfile)" + exit 1 + fi + required_files="${apache22_configfile}" + eval apache22_enable="\${apache22_${profile}_enable:-${apache22_enable}}" + eval apache22_flags="\${apache22_${profile}_flags:-${apache22_flags}}" + eval apache22_http_accept_enable="\${apache22_${profile}_http_accept_enable:-${apache22_http_accept_enable}}" + eval apache22limits_enable="\${apache22limits_${profile}_enable:-${apache22limits_enable}}" + eval apache22limits_args="\${apache22limits_${profile}_args:-${apache22limits_args}}" + apache22_flags="-f ${apache22_configfile} -c \"PidFile ${pidfile}\" ${apache22_flags}" + else + echo "$0: extra argument ignored" + fi +else + if [ "x${apache22_profiles}" != "x" -a "x$1" != "x" -a "x$1" != "xrestart" ]; then + for profile in ${apache22_profiles}; do + echo "===> apache22 profile: ${profile}" + $0 $1 ${profile} + retcode="$?" + if [ "0${retcode}" -ne 0 ]; then + failed="${profile} (${retcode}) ${failed:-}" + else + success="${profile} ${success:-}" + fi + done + exit 0 + fi +fi -[ -z "$apache22_enable" ] && apache22_enable="NO" -[ -z "$apache22_flags" ] && apache22_flags="" -[ -z "$apache22limits_enable" ] && apache22limits_enable="NO" -[ -z "$apache22limits_args" ] && apache22limits_args="-e -C daemon" -[ -z "$apache22_http_accept_enable" ] && apache22_http_accept_enable="NO" - -load_rc_config $name - -if checkyesno apache22_http_accept_enable -then - if ! /sbin/kldstat -q -m accf_http - then +if checkyesno apache22_http_accept_enable; then + if ! /sbin/kldstat -q -m accf_http; then /sbin/kldload accf_http fi else - apache22_flags="-DNOHTTPACCEPT $apache22_flags" + apache22_flags="${apache22_flags} -DNOHTTPACCEPT" fi +apache22_requirepidfile() +{ + if [ ! "0`check_pidfile ${pidfile} ${command}`" -gt 1 ]; then + echo "${name} not running? (check $pidfile)." + exit 1 + fi +} + apache22_checkconfig() { - echo "Performing sanity check on apache22 configuration:" - ${command} ${apache22_flags} -t + echo "Performing sanity check of apache22 configuration:" + eval ${command} ${apache22_flags} -t } -apache22_graceful() { - echo "Performing a graceful restart" - ${command} -k graceful +apache22_graceful() +{ + apache22_requirepidfile + + echo "Performing a graceful restart." + eval ${command} ${apache22_flags} -k graceful } -apache22_gracefulstop() { - echo "Performing a graceful stop" - ${command} -k graceful-stop +apache22_gracefulstop() +{ + apache22_requirepidfile + + echo "Performing a graceful stop." + eval ${command} ${apache22_flags} -k graceful-stop } -apache22_precmd() +apache22_precmd() { - if test -f %%PREFIX%%/sbin/envvars - then + apache22_checkconfig + + if [ -f %%PREFIX%%/sbin/envvars ]; then . %%PREFIX%%/sbin/envvars fi - if checkyesno apache22limits_enable - then + if checkyesno apache22limits_enable; then eval `/usr/bin/limits ${apache22limits_args}` 2>/dev/null else return 0 - fi - + fi } -extra_commands="reload graceful gracefulstop" +extra_commands="reload graceful gracefulstop configtest" run_rc_command "$1" --- www-apache22-files-apache.sh.diff ends here --- >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200601010453.k014rTXX063949>