Skip to main content

I migrated a virtual machine running the Apache 2 web server software on Debian wheezy GNU/Linux from Bytemark's legacy virtual machine infrastructure to their new BigV infrastructure. Staging this on my internal virtual infrastructure worked without a hitch. However, on the true infrastructure, Apache failed to start on boot with the following message. It would restart without issue if I then logged on and started it manually.

[....] Starting web server: apache2(99)Cannot assign requested address: make_sock: could not bind to address [2001:x:x:x::x]:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.
 failed!

Some debugging showed the interface's IP addresses to be in a tentative state during boot. In this state it would appear that you cannot bind to the IP address.

2: eth0:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
[...]
    inet6 2001:x:x:x::x/64 scope global tentative deprecated
       valid_lft forever preferred_lft forever

The solution was to create an init script to wait for the IPv6 addresses to become available before allowing the Apache init script to run. Note that I also pre-depend on openvpn so that I can also listen on the VPN addresses. Create the script /etc/init.d/apache2-delay owned by root with execute permissions.

#!/bin/sh
### BEGIN INIT INFO
# Provides:          apache2-delay
# Required-Start:    openvpn
# Required-Stop:     openvpn
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Start-Before:    apache2
# Short-Description: Pre-load apache2 dependencies
### END INIT INFO

# Ewan Parker 24th February 2015

set -e

SCRIPTNAME="${0##*/}"
SCRIPTNAME="${SCRIPTNAME##[KS][0-9][0-9]}"

. /lib/lsb/init-functions

test -f /etc/default/rcS && . /etc/default/rcS

case $1 in
        start)
                log_daemon_msg "Loading apache2 pre-requisites" "openvpn"
                #ifconfig >/tmp/apache-delay
                #ip addr show >>/tmp/apache-delay
                while [ `ip addr show | grep tentative | wc -l` -ne 0 ]; do
                        sleep 1
                        log_progress_msg "tentative"
                done
                log_end_msg 0
        ;;
        stop)
                log_daemon_msg "Unloading apache2 pre-requisites" "none"
                log_end_msg 0
        ;;
        status)
                exit 0
        ;;
        *)
                log_success_msg "Usage: /etc/init.d/apache2$DIR_SUFFIX {start|stop|status}"
                exit 1
        ;;
esac

Now activate this init script by running insserv apache2-delay.

Classifications