I posted this patch to start some discussion here. I'm not the first to notice this problem but I was, until now, hesitant to change the systemd service file until now. The reason for this was that waiting for network-online.target could delay boot time. Please see systemd network target docs here [1].
As stated in the commit message, the common reason I was asked to change this in RHEL/Fedora was due to attempting to bind to a non-existent IP address, but that can be overcome with 'option transparent'. However I recently was notified that DNS resolution will fail when haproxy starts if the network is not fully online. Thus I suggested the patch. I also found this discussion [2], but noticed that the upstream service file had not been modified. Cheers, Ryan [1] https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/ [2] https://discourse.haproxy.org/t/haproxy-fails-on-restart/3469/10 On Mon, Jun 15, 2020 at 12:03 PM Ryan O'Hara <[email protected]> wrote: > Change systemd service file to wait for network to be completely > online. This solves two problems: > > If haproxy is configured to bind to IP address(es) that are not yet > assigned, haproxy would previously fail. The workaround is to use > "option transparent". > > If haproxy us configured to use a resolver to resolve servers via DNS, > haproxy would previously fail due to the fact that the network is not > fully online yet. This is the most compelling reason for this patch. > > Signed-off-by: Ryan O'Hara <[email protected]> > --- > contrib/systemd/haproxy.service.in | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/contrib/systemd/haproxy.service.in b/contrib/systemd/ > haproxy.service.in > index 9b7c3d1bb..05fc59579 100644 > --- a/contrib/systemd/haproxy.service.in > +++ b/contrib/systemd/haproxy.service.in > @@ -1,6 +1,7 @@ > [Unit] > Description=HAProxy Load Balancer > -After=network.target > +After=network-online.target > +Wants=network-online.target > > [Service] > EnvironmentFile=-/etc/default/haproxy > -- > 2.25.1 > > >

