简体   繁体   中英

Failing to start systemd service

I have written the following systemd service to login at the wireless at boot:

[Unit]
Description=Wireless network connectivity (%i)
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-%i-device
After=sys-subsystem-net-devices-%i-device

[Service]
Type=oneshot
RemainAfterExit=yes

ExecStart=/usr/bin/ip link set dev %i up
ExecStart=/usr/bin/wpa_supplicant -B -i %i -c /etc/wpa_supplicant/wpa_supplicant.conf
ExecStart=/usr/bin/dhcpcd %i

ExecStop=/usr/bin/ip link set dev %i down

[Install]
WantedBy=multi-user.target

I then enable it but I get the following error every time I boot my computer:

[abc@arch ~]$ systemctl --failed
  UNIT                            LOAD   ACTIVE SUB    DESCRIPTION
● network-wireless@wlp3s0.service loaded failed failed Wireless network connectivity (wlp3s0)

However if I manually start this service after boot with:

systemctl start network-wireless@xlp3s0

the service starts as expected.

This is the content of wpa_supplicant.conf

ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=wheel
network={
        ssid="TeliaGateway30-91-8F-1C-B2-29"
        #psk="A80871A90A"
        psk=b4d8a1e9ad665eed0178fea6f141134e795e15183a661848b371a41bb73a6844
}

Why is this services starting ok when starting it manually but not at boot and how can I change it to start at boot?

EDIT: Added error output: This is what error im getting:

[abc@arch ~]$ journalctl -b -u network-wireless@wlp3s0.service
-- Logs begin at Sat 2015-08-22 12:50:42 CEST, end at Sun 2015-08-23 22:15:26 CEST. --
Aug 23 21:23:36 arch systemd[1]: Starting Wireless network connectivity (wlp3s0)...
Aug 23 21:23:36 arch ip[274]: Cannot find device "wlp3s0"
Aug 23 21:23:36 arch systemd[1]: network-wireless@wlp3s0.service: Main process exited, code=exited, status=1/FAILURE
Aug 23 21:23:36 arch systemd[1]: Failed to start Wireless network connectivity (wlp3s0).
Aug 23 21:23:37 arch systemd[1]: network-wireless@wlp3s0.service: Unit entered failed state.
Aug 23 21:23:37 arch systemd[1]: network-wireless@wlp3s0.service: Failed with result 'exit-code'.
Aug 23 21:25:11 arch systemd[1]: Starting Wireless network connectivity (wlp3s0)...
Aug 23 21:25:11 arch dhcpcd[424]: wlp3s0: waiting for carrier
Aug 23 21:25:16 arch dhcpcd[424]: wlp3s0: carrier acquired
Aug 23 21:25:16 arch dhcpcd[424]: DUID 00:01:00:01:1d:6b:6b:e6:10:0d:7f:b7:30:f3
Aug 23 21:25:16 arch dhcpcd[424]: wlp3s0: IAID c1:c4:73:e0
Aug 23 21:25:16 arch dhcpcd[424]: wlp3s0: soliciting an IPv6 router
Aug 23 21:25:16 arch dhcpcd[424]: wlp3s0: rebinding lease of 192.168.1.85
Aug 23 21:25:21 arch dhcpcd[424]: wlp3s0: leased 192.168.1.85 for 3600 seconds
Aug 23 21:25:21 arch dhcpcd[424]: wlp3s0: adding route to 192.168.1.0/24
Aug 23 21:25:21 arch dhcpcd[424]: wlp3s0: adding default route via 192.168.1.1
Aug 23 21:25:21 arch dhcpcd[424]: forked to background, child pid 477
Aug 23 21:25:21 arch dhcpcd[424]: wlp3s0: waiting for carrier
Aug 23 21:25:21 arch dhcpcd[424]: wlp3s0: carrier acquired
Aug 23 21:25:21 arch dhcpcd[424]: DUID 00:01:00:01:1d:6b:6b:e6:10:0d:7f:b7:30:f3
Aug 23 21:25:21 arch dhcpcd[424]: wlp3s0: IAID c1:c4:73:e0
Aug 23 21:25:21 arch dhcpcd[424]: wlp3s0: soliciting an IPv6 router
Aug 23 21:25:21 arch dhcpcd[424]: wlp3s0: rebinding lease of 192.168.1.85
Aug 23 21:25:21 arch dhcpcd[424]: wlp3s0: leased 192.168.1.85 for 3600 seconds
Aug 23 21:25:21 arch dhcpcd[424]: wlp3s0: adding route to 192.168.1.0/24
Aug 23 21:25:21 arch dhcpcd[424]: wlp3s0: adding default route via 192.168.1.1
Aug 23 21:25:21 arch dhcpcd[424]: forked to background, child pid 477
Aug 23 21:25:21 arch systemd[1]: Started Wireless network connectivity (wlp3s0).
Aug 23 21:25:28 arch dhcpcd[477]: wlp3s0: no IPv6 Routers available
Aug 23 22:15:09 arch dhcpcd[477]: wlp3s0: carrier lost
Aug 23 22:15:09 arch dhcpcd[477]: wlp3s0: deleting route to 192.168.1.0/24
Aug 23 22:15:09 arch dhcpcd[477]: wlp3s0: deleting default route via 192.168.1.1
Aug 23 22:15:13 arch dhcpcd[477]: wlp3s0: carrier acquired
Aug 23 22:15:14 arch dhcpcd[477]: wlp3s0: IAID c1:c4:73:e0
Aug 23 22:15:14 arch dhcpcd[477]: wlp3s0: soliciting an IPv6 router
Aug 23 22:15:14 arch dhcpcd[477]: wlp3s0: rebinding lease of 192.168.1.85
Aug 23 22:15:19 arch dhcpcd[477]: wlp3s0: leased 192.168.1.85 for 3600 seconds
Aug 23 22:15:19 arch dhcpcd[477]: wlp3s0: adding route to 192.168.1.0/24
Aug 23 22:15:19 arch dhcpcd[477]: wlp3s0: adding default route via 192.168.1.1
Aug 23 22:15:19 arch dhcpcd[477]: wlp3s0: removing route to 192.168.1.0/24
Aug 23 22:15:26 arch dhcpcd[477]: wlp3s0: no IPv6 Routers available

EDIT: I have found one potetential error, it seems as if the network interface changes name from wlan0 during boot, however i have tried starting the service with wlan0 but with no change in the result.

The reason the service stops at boot is because the ip command cannot find the interface. According to the man page for systemd services that is enough reason to fail the service.

As you noticed yourself the interface gets renamed or is not ready yet at boot.

  • You can check if you need to add an After= statement
  • You can check with the systemd-analyze command if the ordering at boot is correct
  • You could split up the service and make it more robust. Most daemons can start fine even if the interface is not ready yet.

Personally I would make dhcpd and wpa_supplicant separate services and use systemd's networkd or an udev rule to bring up the interface (if that is even needed). There are a lot examples of unit files for wpa_supplicant and dhcpd online maybe have look at those?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM