Configuring HAProxy Service on CentOS

I’ve worked with a customer to get a HAProxy load balancer setup on CentOS 8.0 and ran into an issue with the service that was created. If the Linux VM was restarted, HAProxy would fail to start and it appeared to be related to the network not being available.

Looking around the interwebs, I found the option that was added by default was the culprit. In the haproxy.service file there is a [Unit] section that assigns when the service should start up and it was set to:

[Unit]
After=network.target

Which indicates that the HAProxy service would start after the network manager stack is up and not after the actual network interfaces are up and running, which would be an issue for a network app like HAProxy.

The recommendation I found was to use the following which waits until the network is online to start the service.

[Unit]
After=network-online.target

After making this change, a test restart (well, maybe a couple to be sure) showed that this was working as expected and HAProxy was starting up and available after a restart.

Resource: FreeDesktop.org