Why is this systemd service (dhcpcd) not auto-restarting?

This forum is for discussion about general software issues.

Why is this systemd service (dhcpcd) not auto-restarting?

Postby amckinlay » Fri Mar 04, 2016 3:40 am

Goal:

I want dhcpcd to activate automatically on the wlan0 interface when I plug in my USB WiFi device.

Approach:

I modified the systemd service (dhcpcd@.service) according to https://wiki.archlinux.org/index.php/dhcpcd#Timeout_delay. If there is no USB WiFi device or if the device is unplugged, the service should run in the background and wait for the device to be plugged in.

Issue:

The systemd service stops with $this->bbcode_second_pass_code('', 'systemd[1]: dhcpcd@wlan0.service: Unit entered failed state.') and does not restart.

Logs, configuration, commands:

I unplugged a the already-configured USB WiFi device and plugged it back in. Here is the system log from that event and the relevant unit files for the systemd service: https://gist.github.com/anonymous/ee8c700383fe826ce72a.

Caveats:

  • I am using the interface-specific dhcpcd service (dhcpcd@.service) to avoid the race condition with systemd-udevd (https://wiki.archlinux.org/index.php/dhcpcd#dhcpcd_and_systemd_network_interfaces).
  • Simply enabling the interface-specific version of the service only activates dhcpcd at boot, and does not reactivate it if the USB WiFi device is plugged in after boot, or is removed and reinserted.
  • I realize that the conflicting systemd-networkd is running at the same time as dhcpcd in the logs provided. However, this does not explain why the systemd service does not restart automatically. I have retried with systemd-networkd and systemd-resolved disabled to no avail.
amckinlay
 
Posts: 3
Joined: Fri Mar 04, 2016 1:45 am

Re: Why is this systemd service (dhcpcd) not auto-restarting

Postby amckinlay » Fri Mar 04, 2016 4:33 am

I think I found the problem. As evidenced in the gist, the dhcpcd@.service unit is configured with "BindsTo=sys-subsystem-net-devices-%i.device" directive. This directive "declares that this unit is stopped when any of the units listed suddenly disappears" according to https://www.freedesktop.org/software/systemd/man/systemd.unit.html#BindsTo=. When the device is unplugged the following happens in the log:

$this->bbcode_second_pass_code('', 'systemd[1]: Stopping dhcpcd on wlan0...')

The daemon does not restart despite $this->bbcode_second_pass_code('', 'Restart=always') because it was shutdown by systemd.

Perhaps I should edit the ArchWiki to clarify that the timeout/restart workaround does not work for removable networking devices. While I'm sure a another workaround exists (perhaps using udev rules or more systemd), I think I'll just stick to networkd, as it's already enabled by default for my system.

I still wonder why the dhcpcd daemon exits with failure after being shut down by systemd.
amckinlay
 
Posts: 3
Joined: Fri Mar 04, 2016 1:45 am


Return to General

Who is online

Users browsing this forum: No registered users and 25 guests

cron