Say you have a fresh and modern Ubuntu system (say 20.04 LTS Server) installed on real hardware, and you need to deploy one or more network bound services, such as:
In my experience, If you configure a service to bind to anything other than IPv4 0.0.0.0 or IPv6 [::] or to a local/loopback interface, this service will more likely than not fail and not recover upon system reboot.
For instance, if you bind to any of the local, private, public, hosts:
192.168.22.30
or
2601:171c:d401:120a::1001
or
fde8:b0ab:dd91:1010::feeb
you will start and enable them successfully during that session, but will likely fail upon system reboot.
Why? Because it seems that System Units that ship with Ubuntu:
- Do not wait until Network Interfaces are up, or system is actually online
- Even when ethernet has initialized, it might take a few seconds for IPs (statically configured or not) to be ready for binding
- When such a service fails, Ubuntu stock units aren't configured to restart and retry starting the service after a few seconds have elapsed
So my current solution is to modify these Unit files to add a strong dependency on network being up and system being online, and also add a 5 second retry/restart upon startup failure.
But what is the proper way of correcting this?