4

I am trying to run an executable, right before shutdown, that needs NetworkManager running. Here is the service file that I currently have (located in /lib/systemd/system), and it works fine if I have an ethernet connection, but does not work if I only have a wireless connection:

[Unit]
Requires=network.target
Requires=NetworkManager.service
Before=shutdown.target
After=network.target NetworkManager.service

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=MyShutdownExecutable

[Install]
wantedBy=multi-user.target

This is running on an embedded device, and sometimes the user will have an ethernet connection, sometimes only a wireless connection, sometimes both - so this needs to work with all these combinations of network connectivity.

At one point in my testing, during shutdown I saw a message that NetworkManager had shutdown before my executable had run. I was under the impression that having After=NetworkManager.service in my service file should guarantee that NetworkManager should not shutdown until after my executable finishes - which seems to be the case when I have an ethernet connection.

Any help would be appreciated greatly.

1 Answer 1

3

Can you try this as your service file.

[Unit]
After=wpa_supplicant.service dbus.service NetworkManager.service
Requires=wpa_supplicant.service dbus.service NetworkManager.service

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=MyShutdownExecutable

[Install]
WantedBy=multi-user.target

I managed to get my script running with this - the wireless connection was being torn down by wpa supplicant and dbus even thought NetworkManager was still running.

2
  • "wantedBy" should be "WantedBy", otherwise it works great!
    – elmicha
    Jul 31, 2016 at 19:23
  • corrected "WantedBy" - ty elmicha
    – fingletoe
    Apr 10, 2017 at 11:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .