2
I was trying to build a systemd service to run after the networking is up.
/etc/systemd/system/caportal.service
[Unit]
Description=captive portal automation
DefaultDependencies=no
After=local-fs.target
[Service]
Type=oneshot
ExecStart=/sbin/wpa_cli -a /home/pi/test.sh -B
ExecStop=/usr/bin/pkill -f /home/pi/test.sh
RemainAfterExit=yes
[Install]
WantedBy=network.target
But this service does not start at reboot. It start when manually started by sudo systemctl start caportal.service
.
But after reboot, the status information of this service was given below.
● caportal.service - captive portal automation
Loaded: loaded (/etc/systemd/system/caportal.service; enabled)
Active: failed (Result: exit-code) since Thu 2019-04-11 10:59:32 UTC; 3min 3s ago
Process: 287 ExecStart=/sbin/wpa_cli -a /home/pi/test.sh -B (code=exited, status=255)
Main PID: 287 (code=exited, status=255)
Apr 11 10:59:32 raspberrypi systemd[1]: Starting captive portal automation...
Apr 11 10:59:32 raspberrypi wpa_cli[287]: Failed to connect to non-global ctrl_ifname: (null) error: No such file or directory
Apr 11 10:59:32 raspberrypi systemd[1]: caportal.service: main process exited, code=exited, status=255/n/a
Apr 11 10:59:32 raspberrypi systemd[1]: Failed to start captive portal automation.
Apr 11 10:59:32 raspberrypi systemd[1]: Unit caportal.service entered failed state.
How to start the service at reboot before the network start?
Thanks @grawity. Can I start the script after wpa_supplicant.service? Also How to view the order in which systemd process each service? – mcv – 2019-04-12T04:00:05.723
Sure,
[Unit] After=wpa_supplicant.service
. But you can't guarantee that it'll run before or after wpa_supplicant has done something-or-other, only that it'll run after it has "started". Usesystemctl list-dependencies --after
,--before
, and maybesystemd-analyze dot | dot -Tx11
? – user1686 – 2019-04-12T04:20:24.500yeah, I have already tried that
After=wpa_supplicant.service
. But it wasn't working. Now it shows the service as inactive – mcv – 2019-04-12T04:57:11.273systemctl list-dependencies --after
, this list not showing wpa_supplicant.service` – mcv – 2019-04-12T04:58:14.283Did you tell it to list caportal.service? – user1686 – 2019-04-12T04:59:22.660
Yeah now i got the list, but the list shows that
local-fs.target
is run afterwpa_supplicant.service
. Then why wpa_cli is got error? – mcv – 2019-04-12T05:06:20.027why the service is showing
inactive
and Process is showingsuccess
. What does it mean? Butps
command showstest.sh
is not running. – mcv – 2019-04-12T05:15:06.213