[SCM] Debian packaging for apache2 branch, master, updated. debian/2.2.22-3-34-g2f4956a
Arno Töll
arno at debian.org
Mon Jun 11 21:53:59 UTC 2012
The following commit has been merged in the master branch:
commit 2f4956ae99299e752b43455f8627655ae5012b66
Author: Arno Töll <arno at debian.org>
Date: Mon Jun 11 23:53:34 2012 +0200
Revert "Improve the init script when used with fancy output"
This reverts commit 425eeefca35b340e619edcc8ba06a8ca95919e3c.
diff --git a/debian/apache2.2-common.apache2.init b/debian/apache2.2-common.apache2.init
old mode 100755
new mode 100644
index 43986a1..f49cd55
--- a/debian/apache2.2-common.apache2.init
+++ b/debian/apache2.2-common.apache2.init
@@ -9,36 +9,34 @@
# Short-Description: Start/stop apache2 web server
### END INIT INFO
-DESC="web server"
-NAME=apache2
-DAEMON=/usr/sbin/$NAME
+set -e
SCRIPTNAME="${0##*/}"
SCRIPTNAME="${SCRIPTNAME##[KS][0-9][0-9]}"
if [ -n "$APACHE_CONFDIR" ] ; then
- if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
- DIR_SUFFIX="${APACHE_CONFDIR##/etc/apache2-}"
- else
- DIR_SUFFIX=
- fi
+ if [ "${APACHE_CONFDIR##/etc/apache2-}" != "${APACHE_CONFDIR}" ] ; then
+ DIR_SUFFIX="${APACHE_CONFDIR##/etc/apache2-}"
+ else
+ DIR_SUFFIX=
+ fi
elif [ "${SCRIPTNAME##apache2-}" != "$SCRIPTNAME" ] ; then
- DIR_SUFFIX="-${SCRIPTNAME##apache2-}"
- APACHE_CONFDIR=/etc/apache2$DIR_SUFFIX
+ DIR_SUFFIX="-${SCRIPTNAME##apache2-}"
+ APACHE_CONFDIR=/etc/apache2$DIR_SUFFIX
else
- DIR_SUFFIX=
- APACHE_CONFDIR=/etc/apache2
+ DIR_SUFFIX=
+ APACHE_CONFDIR=/etc/apache2
fi
if [ -z "$APACHE_ENVVARS" ] ; then
- APACHE_ENVVARS=$APACHE_CONFDIR/envvars
+ APACHE_ENVVARS=$APACHE_CONFDIR/envvars
fi
export APACHE_CONFDIR APACHE_ENVVARS
ENV="env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin"
if [ "$APACHE_CONFDIR" != /etc/apache2 ] ; then
- ENV="$ENV APACHE_CONFDIR=$APACHE_CONFDIR"
+ ENV="$ENV APACHE_CONFDIR=$APACHE_CONFDIR"
fi
if [ "$APACHE_ENVVARS" != "$APACHE_CONFDIR/envvars" ] ; then
- ENV="$ENV APACHE_ENVVARS=$APACHE_ENVVARS"
+ ENV="$ENV APACHE_ENVVARS=$APACHE_ENVVARS"
fi
@@ -52,267 +50,237 @@ HTCACHECLEAN_OPTIONS=""
APACHE_HTTPD=$(. $APACHE_ENVVARS && echo $APACHE_HTTPD)
if [ -z "$APACHE_HTTPD" ] ; then
- APACHE_HTTPD=/usr/sbin/apache2
+ APACHE_HTTPD=/usr/sbin/apache2
fi
-
-# Read configuration variable file if it is present
-if [ -f /etc/default/apache2$DIR_SUFFIX ] ; then
- . /etc/default/apache2$DIR_SUFFIX
-elif [ -f /etc/default/apache2 ] ; then
- . /etc/default/apache2
+if [ ! -x $APACHE_HTTPD ] ; then
+ echo "No apache MPM package installed"
+ exit 0
fi
-PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE)
-
-# Load the VERBOSE setting and other rcS variables
-. /lib/init/vars.sh
. /lib/lsb/init-functions
+test -f /etc/default/rcS && . /etc/default/rcS
+
+if [ -f /etc/default/apache2$DIR_SUFFIX ] ; then
+ . /etc/default/apache2$DIR_SUFFIX
+elif [ -f /etc/default/apache2 ] ; then
+ . /etc/default/apache2
+fi
-# Now, set defaults:
APACHE2CTL="$ENV /usr/sbin/apache2ctl"
HTCACHECLEAN="$ENV /usr/sbin/htcacheclean"
-PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE)
-APACHE2_INIT_MESSAGE=""
-
-
-apache_wait_stop() {
- local STATUS=$1
- PIDTMP=$(pidofproc $DAEMON -p $PIDFILE)
- if [ -n ${PIDTMP:-} ] && kill -0 "${PIDTMP:-}" 2> /dev/null; then
- local i=0
- while kill -0 "${PIDTMP:-}" 2> /dev/null; do
- if [ $i = '60' ]; then
- break
- STATUS=2
- fi
- log_progress_msg "."
- sleep 1
- i=$(($i+1))
- done
- return $STATUS
- else
- return $STATUS
- fi
-}
+PIDFILE=$(. $APACHE_ENVVARS && echo $APACHE_PID_FILE)
+if [ -z "$PIDFILE" ] ; then
+ echo ERROR: APACHE_PID_FILE needs to be defined in $APACHE_ENVVARS >&2
+ exit 2
+fi
-#
-# Function that starts the daemon/service
-#
-do_start()
-{
- # Return
- # 0 if daemon has been started
- # 1 if daemon was already running
- # 2 if daemon could not be started
+check_htcacheclean() {
+ [ "$HTCACHECLEAN_MODE" = "daemon" ] || return 1
- if pidofproc "$DAEMON" -p $PIDFILE > /dev/null 2>&1 ; then
- return 1
- fi
+ [ "$HTCACHECLEAN_RUN" = "yes" ] && return 0
- if $APACHE2CTL configtest > /dev/null 2>&1; then
- $APACHE2CTL start
- return $?
- else
- APACHE2_INIT_MESSAGE="The apache2$DIR_SUFFIX configtest failed. Please run '$APACHE2CTL configtest' manually and read the log file to discover problems"
- return 2
- fi
+ MODSDIR=$(. $APACHE_ENVVARS && echo $APACHE_MODS_ENABLED)
+ [ "$HTCACHECLEAN_RUN" = "auto" \
+ -a -e ${MODSDIR:-$APACHE_CONFDIR/mods-enabled}/disk_cache.load ] && \
+ return 0
+
+ return 1
}
-#
-# Function that stops the daemon/service
-#
-do_stop()
-{
- # Return
- # 0 if daemon has been stopped
- # 1 if daemon was already stopped
- # 2 if daemon could not be stopped
- # other if a failure occurred
-
- # either "stop" or "graceful-stop"
- local STOP=$1
- # can't use pidofproc from LSB here
- local AP_RET=0
-
- if pidof $DAEMON > /dev/null 2>&1 ; then
- if [ -e $PIDFILE ] && pidof $DAEMON | tr ' ' '\n' | grep -w $(cat $PIDFILE) > /dev/null 2>&1 ; then
- AP_RET=2
- else
- AP_RET=1
- fi
- else
- AP_RET=0
- fi
-
- # AP_RET is:
- # 0 if Apache (whichever) is not running
- # 1 if Apache (whichever) is running
- # 2 if Apache from the PIDFILE is running
-
- if [ $AP_RET = 0 ] ; then
- return 1
- fi
-
- if [ $AP_RET = 2 ] && $APACHE2CTL configtest > /dev/null 2>&1; then
- $APACHE2CTL $STOP > /dev/null 2>&1
- apache_wait_stop $?
- return $?
- else
- if [ $AP_RET = 2 ]; then
- APACHE2_INIT_MESSAGE="The apache2$DIR_SUFFIX configtest failed, so we are trying to kill it manually. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!"
- killproc -p $PIDFILE $DAEMON
- apache_wait_stop $?
- return $?
- elif [ $AP_RET = 1 ] ; then
- APACHE2_INIT_MESSAGE="There are processes named 'apache2' running which do not match your pid file which are left untouched in the name of safety, Please review the situation by hand".
- return 2
- fi
- fi
-
+start_htcacheclean() {
+ if [ ! -d "$HTCACHECLEAN_PATH" ] ; then
+ echo "... directory $HTCACHECLEAN_PATH does not exist!" >&2
+ return 1
+ fi
+ $HTCACHECLEAN $HTCACHECLEAN_OPTIONS -d$HTCACHECLEAN_DAEMON_INTERVAL \
+ -i -p$HTCACHECLEAN_PATH -l$HTCACHECLEAN_SIZE
}
-
-#
-# Function that sends a SIGHUP to the daemon/service
-#
-do_reload() {
- if $APACHE2CTL configtest > /dev/null 2>&1; then
- $APACHE2CTL graceful > /dev/null 2>&1
- return $?
- else
- APACHE2_INIT_MESSAGE="The apache2$DIR_SUFFIX configtest failed. Not doing anything."
- return 2
- fi
+stop_htcacheclean() {
+ pkill -P 1 -f "htcacheclean.* -p$HTCACHECLEAN_PATH " 2> /dev/null || echo ...not running
}
-
-check_htcacheclean() {
- [ "$HTCACHECLEAN_MODE" = "daemon" ] || return 1
- [ "$HTCACHECLEAN_RUN" = "yes" ] && return 0
-
- MODSDIR=$(. $APACHE_ENVVARS && echo $APACHE_MODS_ENABLED)
- [ "$HTCACHECLEAN_RUN" = "auto" \
- -a -e ${MODSDIR:-$APACHE_CONFDIR/mods-enabled}/disk_cache.load ] && \
- return 0
- return 1
+pidof_apache() {
+ # if there is actually an apache2 process whose pid is in PIDFILE,
+ # print it and return 0.
+ if [ -e "$PIDFILE" ]; then
+ if pidof apache2 | tr ' ' '\n' | grep -w $(cat $PIDFILE); then
+ return 0
+ fi
+ fi
+ return 1
}
-start_htcacheclean() {
- $HTCACHECLEAN $HTCACHECLEAN_OPTIONS -d$HTCACHECLEAN_DAEMON_INTERVAL \
- -i -p$HTCACHECLEAN_PATH -l$HTCACHECLEAN_SIZE
+apache_stop() {
+ if $APACHE2CTL configtest > /dev/null 2>&1; then
+ # if the config is ok than we just stop normaly
+ $APACHE2CTL stop 2>&1 | grep -v 'not running' >&2 || true
+ else
+ # if we are here something is broken and we need to try
+ # to exit as nice and clean as possible
+ PID=$(pidof_apache) || true
+
+ if [ "${PID}" ]; then
+ # in this case it is everything nice and dandy and we kill apache2
+ echo
+ log_warning_msg "The apache2$DIR_SUFFIX configtest failed, so we are trying to kill it manually. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!"
+ kill $PID
+ elif [ "$(pidof apache2)" ]; then
+ if [ "$VERBOSE" != no ]; then
+ echo " ... failed!"
+ echo "You may still have some apache2 processes running. There are"
+ echo "processes named 'apache2' which do not match your pid file,"
+ echo "and in the name of safety, we've left them alone. Please review"
+ echo "the situation by hand."
+ fi
+ return 1
+ fi
+ fi
}
-stop_htcacheclean() {
- pkill -P 1 -f "htcacheclean.* -p$HTCACHECLEAN_PATH " 2> /dev/null || return 1
+apache_wait_stop() {
+ # running ?
+ PIDTMP=$(pidof_apache) || true
+ if kill -0 "${PIDTMP:-}" 2> /dev/null; then
+ PID=$PIDTMP
+ fi
+
+ apache_stop
+
+ # wait until really stopped
+ if [ -n "${PID:-}" ]; then
+ i=0
+ while kill -0 "${PID:-}" 2> /dev/null; do
+ if [ $i = '60' ]; then
+ break;
+ else
+ if [ $i = '0' ]; then
+ echo -n " ... waiting "
+ else
+ echo -n "."
+ fi
+ i=$(($i+1))
+ sleep 1
+ fi
+ done
+ fi
}
-
-# Sanity checks. They need to occur after function declarations
-[ -x $APACHE_HTTPD ] || exit 0
-
-if [ ! -x $APACHE_HTTPD ] ; then
- echo "No apache MPM package installed"
- exit 0
-fi
-
-if [ -z "$PIDFILE" ] ; then
- echo ERROR: APACHE_PID_FILE needs to be defined in $APACHE_ENVVARS >&2
- exit 2
-fi
-
-if check_htcacheclean ; then
- if [ ! -d "$HTCACHECLEAN_PATH" ] ; then
- echo "htcacheclean is configured, but directory $HTCACHECLEAN_PATH does not exist!" >&2
- exit 2
- fi
-fi
-
-
-
-case "$1" in
- start)
- [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
- do_start
- RET_STATUS=$?
- case "$RET_STATUS" in
- 0|1)
- [ "$VERBOSE" != no ] && log_end_msg 0
- [ "$VERBOSE" != no ] && [ $RET_STATUS = 1 ] && log_warning_msg "Server was already running"
- if check_htcacheclean ; then
- [ "$VERBOSE" != no ] && log_daemon_msg "Starting HTTP cache cleaning daemon" "htcacheclean"
- start_htcacheclean
- [ "$VERBOSE" != no ] && log_end_msg $?
- fi
- ;;
- 2)
- [ "$VERBOSE" != no ] && log_end_msg 1
- [ "$VERBOSE" != no ] && [ "x$APACHE2_INIT_MESSAGE" != "x" ] && log_failure_msg "$APACHE2_INIT_MESSAGE"
- ;;
- esac
+case $1 in
+ start)
+ log_daemon_msg "Starting web server" "apache2"
+ if $APACHE2CTL start; then
+ if check_htcacheclean ; then
+ log_progress_msg htcacheclean
+ start_htcacheclean || log_end_msg 1
+ fi
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
;;
- stop|graceful-stop)
- [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
- do_stop "$1"
- RET_STATUS=$?
- case "$RET_STATUS" in
- 0|1)
- [ "$VERBOSE" != no ] && log_end_msg 0
- [ "$VERBOSE" != no ] && [ $RET_STATUS = 1 ] && log_warning_msg "Server was not running"
-
- ;;
- 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
- esac
- [ "$VERBOSE" != no ] && [ "x$APACHE2_INIT_MESSAGE" != "x" ] && log_warning_msg "$APACHE2_INIT_MESSAGE"
-
- if check_htcacheclean ; then
- [ "$VERBOSE" != no ] && log_daemon_msg "Stopping HTTP cache cleaning daemon" "htcacheclean"
- stop_htcacheclean
- [ "$VERBOSE" != no ] && log_end_msg $?
- fi
-
+ stop)
+ if check_htcacheclean ; then
+ log_daemon_msg "Stopping web server" "htcacheclean"
+ stop_htcacheclean
+ log_progress_msg "apache2"
+ else
+ log_daemon_msg "Stopping web server" "apache2"
+ fi
+ if apache_wait_stop; then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
+ ;;
+ graceful-stop)
+ if check_htcacheclean ; then
+ log_daemon_msg "Stopping web server" "htcacheclean"
+ stop_htcacheclean
+ log_progress_msg "apache2"
+ else
+ log_daemon_msg "Stopping web server" "apache2"
+ fi
+ if $APACHE2CTL graceful-stop; then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
+ ;;
+ reload | force-reload | graceful)
+ log_daemon_msg "Reloading web server config"
+ if pidof_apache > /dev/null ; then
+ log_progress_msg "apache2"
+ if ! $APACHE2CTL configtest > /dev/null 2>&1; then
+ log_end_msg 1
+ $APACHE2CTL configtest || true
+ exit 1
+ fi
+ if $APACHE2CTL graceful $2 ; then
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
+ else
+ log_progress_msg "apache2 not running"
+ log_end_msg 0
+ fi
+ ;;
+ restart)
+ if ! $APACHE2CTL configtest > /dev/null 2>&1; then
+ $APACHE2CTL configtest || true
+ log_end_msg 1
+ exit 1
+ fi
+ if check_htcacheclean ; then
+ log_daemon_msg "Restarting web server" "htcacheclean"
+ stop_htcacheclean
+ log_progress_msg apache2
+ else
+ log_daemon_msg "Restarting web server" "apache2"
+ fi
+ PID=$(pidof_apache) || true
+ if ! apache_wait_stop; then
+ log_end_msg 1 || true
+ fi
+ if $APACHE2CTL start; then
+ if check_htcacheclean ; then
+ start_htcacheclean || log_end_msg 1
+ fi
+ log_end_msg 0
+ else
+ log_end_msg 1
+ fi
;;
- status)
- status_of_proc "apache2" "$NAME" -p $PIDFILE && exit 0 || exit $?
+ start-htcacheclean)
+ log_daemon_msg "Starting htcacheclean"
+ start_htcacheclean || log_end_msg 1
+ log_end_msg 0
;;
- reload|force-reload|graceful)
- log_daemon_msg "Reloading $DESC" "$NAME"
- do_reload
- log_end_msg $?
- [ "$VERBOSE" != no ] && [ "x$APACHE2_INIT_MESSAGE" != "x" ] && log_warning_msg "$APACHE2_INIT_MESSAGE"
+ stop-htcacheclean)
+ log_daemon_msg "Stopping htcacheclean"
+ stop_htcacheclean
+ log_end_msg 0
;;
- restart)
- log_daemon_msg "Restarting $DESC" "$NAME"
- do_stop
- case "$?" in
- 0|1)
- do_start
- case "$?" in
- 0) log_end_msg 0 ;;
- 1) log_end_msg 1 ;; # Old process is still running
- *) log_end_msg 1 ;; # Failed to start
- esac
- ;;
- *)
- # Failed to stop
- log_end_msg 1
- ;;
- esac
+ status)
+ PID=$(pidof_apache) || true
+ if [ -n "$PID" ]; then
+ echo "Apache2$DIR_SUFFIX is running (pid $PID)."
+ exit 0
+ else
+ echo "Apache2$DIR_SUFFIX is NOT running."
+ if [ -e "$PIDFILE" ]; then
+ exit 1
+ else
+ exit 3
+ fi
+ fi
;;
- start-htcacheclean)
- log_daemon_msg "Starting htcacheclean"
- start_htcachelean
- log_end_msg $?
- ;;
- stop-htcacheclean)
- log_daemon_msg "Stopping htcacheclean"
- stop_htcacheclean
- log_end_msg $?
- ;;
- *)
- echo "Usage: $SCRIPTNAME {start|stop|graceful-stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean}" >&2
- exit 3
+ *)
+ log_success_msg "Usage: /etc/init.d/apache2$DIR_SUFFIX {start|stop|graceful-stop|restart|reload|force-reload|start-htcacheclean|stop-htcacheclean|status}"
+ exit 1
;;
esac
diff --git a/debian/changelog b/debian/changelog
index 8cc4032..9feaa04 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -2,8 +2,6 @@ apache2 (2.2.22-8) UNRELEASED; urgency=low
* Fix "contradictory comment in /etc/apache2/apache2.conf about the
.load suffix" (Closes: #676975). Hopefully you are now happy, Vincent. :-)
- * Rewrite most parts of the init script to make it more readable and improve
- visual feedback when fancy output is in use.
-- Arno Töll <arno at debian.org> Mon, 11 Jun 2012 11:14:57 +0200
--
Debian packaging for apache2
More information about the Pkg-apache-commits
mailing list