You are not logged in.
[This is my first time creating a thread, I apoligize if there is a more suitable category]
Hello,
I would like to run a command at shutdown before stopping a specific service (connman). I need the command to finish before stopping connman as well.
Is there a good way to do this? I tried searching, but it seems systemd is a bit finnicky when it comes to shutdowns.
I'd like to achieve this without modifying connman.service (Though this would probably work for me)
What is the best way to do this?
Thanks,
Jacob
Last edited by frash23 (2014-12-21 13:59:03)
Amateur web developer & Linux enthusiast
Offline
Hi
I'm not sure if it would work, but from logic, creating a service file for your command with an "After=" dependency to connman might do it. Assuming that systemd passes the dependencies in reverse order when shutting down...
Plus use "ExecStop=" to make your command execute at stopping.
You gotta try this out.
Regards
Edit: To test/debug you can probably simply stop connman and see if it pulls the dep (instead of shutting down completely).
Edit2: Maybe better better use "ExecStop=" inside the connman service files. As you mentioned you copy the original service file from /usr/lib/systemd/system to /etc/systemd/system and make your modifications there. This is the correct way to modify service files.
Or then do it with a "config" directory, analog to how it's done here: https://wiki.archlinux.org/index.php/au … al_console
Reference 'man systemd.service':
ExecStop=
Commands to execute to stop the service started via ExecStart=. This argument takes
multiple command lines, following the same scheme as described for ExecStart= above. Use of
this setting is optional. After the commands configured in this option are run, all
processes remaining for a service are terminated according to the KillMode= setting (see
systemd.kill(5)). If this option is not specified, the process is terminated immediately
when service stop is requested. Specifier and environment variable substitution is
supported (including $MAINPID, see above).
Evtl. make sure your links in the .wants directory reference to the correct service file. (Disable and reenable once.)
Last edited by rebootl (2014-12-21 16:51:18)
Personal website: reboot.li
GitHub: github.com/rebootl
Offline