2

I'm trying to run a systemd service at shutdown: it kinda works (it gets called) but it runs after filesystems are unmounted, which is not what I need. So I tried with Before=umount.target and WantedBy=umount.target without any luck (filesystems are unmounted before running the service). When I say "filesystems" I mean all but the root.

Is there any other target to pay attention to?

3
  • 1
    Is it too nasty to mount it again in the service, run your intended function in the service and unmount it back again?
    – esantix
    Commented Jan 24, 2021 at 3:08
  • unix.stackexchange.com/questions/89881/… give some ideas
    – esantix
    Commented Jan 24, 2021 at 3:09
  • 1
    Of course I'll do as you suggest, but I can't believe it doesn't exist a proper way to make it work LOL Commented Jan 24, 2021 at 9:04

1 Answer 1

0

Try adding DefaultDependencies=no to the Unit section of the service file. systemd.service manpage says:

The following dependencies are added unless DefaultDependencies=no is set:

  •   Service units will have dependencies of type Requires= and After= on sysinit.target, a dependency of type After= on basic.target as well
      as dependencies of type Conflicts= and Before= on shutdown.target. These ensure that normal service units pull in basic system
      initialization, and are terminated cleanly prior to system shutdown. Only services involved with early boot or late system shutdown
      should disable this option.

...

1
  • Can you explain why this might help? … … … … … … … … … … … … … … … … … Please do not respond in comments; edit your answer to make it clearer and more complete. Commented Jul 22, 2022 at 20:38

You must log in to answer this question.

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