Score:1

How do you properly fix/prevent when Systemd Units fail when binding to none local IP host/port upon system startup?

vn flag

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:

  • Nginx
  • MySQL
  • PostgreSQL

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:

  1. Do not wait until Network Interfaces are up, or system is actually online
  2. Even when ethernet has initialized, it might take a few seconds for IPs (statically configured or not) to be ready for binding
  3. 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?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.