FS#50441 - [keepalived] Starts before the network is running

Attached to Project: Community Packages
Opened by Bill Mair (red-lichtie) - Friday, 19 August 2016, 00:45 GMT
Last edited by Sébastien Luttringer (seblu) - Sunday, 27 November 2016, 03:23 GMT
Task Type Bug Report
Category Packages
Status Closed
Assigned To Sébastien Luttringer (seblu)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:

The keepalived.service is started before the network is up.

The Unit declaration "After=network.target" isn't sufficient.

I changed the default behaviour using "systemctl edit keepalived.service" and added:

[Unit]
Requires=network-online.target
After=network-online.target

I think that this change should be the default requirement in "/usr/lib/systemd/system/keepalived.service"
This task depends upon

Closed by  Sébastien Luttringer (seblu)
Sunday, 27 November 2016, 03:23 GMT
Reason for closing:  Fixed
Additional comments about closing:  keepalived-1.3.2-1
Comment by Sébastien Luttringer (seblu) - Monday, 22 August 2016, 20:59 GMT
I there any issue with that? AFIK keepalived doesn't need an hard dependency to order network start. If you want to run "systemctl enable network-online".
Comment by Bill Mair (red-lichtie) - Tuesday, 23 August 2016, 12:46 GMT
  • Field changed: Percent Complete (100% → 0%)
The daemon should only start after the network adapters are configured and available. If "network.target" is used, then keepalived starts without having any adapter to configure.
The same applies to shutdown, without networking it can't shutdown and handoff any services and VIPs that it is managing if the devices are taken offline before it is stopped.
Networking has to be a "Required" service.
Debian also has networking as a requirement:
# Required-Start: $syslog $network $remote_fs
# Required-Stop: $syslog $network $remote_fs

Comment by Bill Mair (red-lichtie) - Tuesday, 23 August 2016, 13:07 GMT
I have found the reason for the error that I am seeing.

The network adapter configuration hasn't completed before keepalived is started.

I removed my change to get the exact error message:

Aug 23 11:03:48 cluster-node2 Keepalived_vrrp[295]: (VI_PUB): Cannot find an IP address to use for interface eth0

I am using DHCP to configure the cluster nodes and the adapters get their addresses later, this means that the VIP(s) can not be assigned.
Comment by Bill Mair (red-lichtie) - Wednesday, 24 August 2016, 07:32 GMT
I've been going through the systemd documentation and I now think that the following definition best matches a system administrator's expectations when running keepalived.

------------------------------------------------------------

[Unit]
After=network-online.target remote-fs.target

------------------------------------------------------------

I actually think that "After=remote-fs.target" might be sufficient as remote-fs.target implies "After=network-online.target" according to the systemd documentation:

"By default all remote mounts defined in /etc/fstab pull this service in, in order to make sure the network is up before it is attempted to connect to a network share."

Please see: https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
Comment by Slash Bunny (Slash) - Thursday, 22 September 2016, 02:34 GMT
I am seeing similar problems. Here are the relevant parts of the log which demonstrate keepalived trying and failing before ens3 is ready:

>Sep 21 22:18:04 lb02 systemd[1]: Starting Network Service...
Sep 21 22:18:04 lb02 systemd-networkd[178]: Enumeration completed
Sep 21 22:18:04 lb02 systemd[1]: Started Network Service.
Sep 21 22:18:04 lb02 systemd[1]: Started Keepalive Daemon.
Sep 21 22:18:04 lb02 Keepalived[179]: Starting Keepalived v1.2.24 (09/17,2016)
Sep 21 22:18:04 lb02 Keepalived[179]: Opening file '/etc/keepalived/keepalived.conf'.
Sep 21 22:18:04 lb02 Keepalived_vrrp[187]: Cant find interface ens3 for vrrp_instance VI_1 !!!
Sep 21 22:18:04 lb02 Keepalived_vrrp[187]: VRRP_Instance(VI_1) Unknown interface !
Sep 21 22:18:05 lb02 systemd-networkd[178]: eth0: Renamed to ens3
Sep 21 22:18:05 lb02 systemd-networkd[178]: ens3: Gained carrier
Sep 21 22:18:05 lb02 Keepalived[179]: pid 187 exited with permanent error CONFIG. Terminating
Sep 21 22:18:05 lb02 Keepalived[179]: Stopping
Sep 21 22:18:07 lb02 systemd-networkd[178]: ens3: Gained IPv6LL
Sep 21 22:18:20 lb02 systemd-networkd[178]: ens3: Configured

Altering the After= line to the above suggestions didn't correct the issue.
Comment by Bill Mair (red-lichtie) - Thursday, 22 September 2016, 09:35 GMT
Did you also enable the network-online service ?

One of the following has to be enabled:

systemd-networkd --> systemctl enable systemd-networkd-wait-online.service

NetworkManager --> systemctl enable NetworkManager-wait-online.service

See: https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/#cutthecraphowdoimakenetwork.targetworkforme

Loading...