--- ./apache2 2006/03/02 23:57:11 1.1 +++ ./apache2 2006/03/03 01:11:27 @@ -2,7 +2,7 @@ # Copyright 1999-2005 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -opts="${opts} reload configtest" +opts="${opts} reload configtest check" # this next comment is important, don't remove it - it has to be somewhere in # the init script to kill off a warning that doesn't apply to us @@ -92,3 +92,51 @@ eend $? fi } + +check() { + # get listening sockets + local listen=$(lsof -c apache2 -a -Pni tcp -Fn 2>/dev/null \ + | grep '^n' | grep -v -- '->' | cut -c 2- \ + | sort -n | uniq) + if [ -z "${listen}" ]; then + ewarn "Apache2 not listening on any address :-(" + else + einfo "Apache2 listening on:" + eindent + # loop through ip+port list + for ip_port in ${listen}; do + einfon "${ip_port}, " + local ip=${ip_port%:*} + local port=${ip_port#*:} + case ${port} in + # known HTTP ports + 80|81|8080) + echo -n 'trying HTTP: ' + local res=$(echo -en "HEAD ${CHECK_URI:-/} HTTP/1.0\n\n" \ + | nc -w 3 ${ip} ${port} 2>/dev/null \ + | head -n 1) + ;; + # known HTTPS ports + 443) + echo -n 'trying HTTPS: ' + local res=$(echo -en "HEAD ${CHECK_URI:-/} HTTP/1.0\n\n" \ + | openssl s_client -quiet -connect ${ip_port} 2>/dev/null \ + | head -n 1) + ;; + # unknown ports + *) + echo -n "no idea how to handle port ${port}" + ;; + esac + # did we get a result? + if [ -n "${res}" ]; then + echo "${res}" + eend 0 + else + echo ":-(" + eend 1 + fi + done + eoutdent + fi +}