Apache failed on system boot, when binding to an additional IP

Starting point:

My system (Ubuntu 18.04.1) is a VPS running on KVM. The network with some additional IPs is configured with Netplan.

 

Problem:

The Apache server is running on an additional IP. If the VPS reboots, the apache didn’t start because, it couldn’t be bind on an aditional IP. A log entry like the following can be found:
apachectl[631]: (99)Cannot assign requested address: AH00072: make_sock: could not bind to address [xxxxxxxx]:80

But if you restart Apache after the reboot, it runs as expected!
Strange, isn’t it?

 

Solution:

Ok, I couldn’t find the exact reason of this reason. But I think, there is a strange timing issue on reboot. The network isn’t completely up before Apache is starting.

To solve the problem, just edited the section ‘Unit’ in the file /lib/systemd/system/apache2.service and replace

After=network.target remote-fs.target nss-lookup.target

with

Requires=network-online.target
After=network-online.target remote-fs.target nss-lookup.target

That’s it!

More information about the network-target can be found her: https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/

, ,

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: