3

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.

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.