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?

  • 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 Jan 24 '21 at 03:08
  • https://unix.stackexchange.com/questions/89881/systemd-umount-device-after-service-which-depends-on-it-finishesmight give some ideas – esantix Jan 24 '21 at 03: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 – user3534974 Jan 24 '21 at 09:04

1 Answers1

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.

...

elucches
  • 1
  • 1
  • Can you explain why this might help? … … … … … … … … … … … … … … … … … Please do not respond in comments; [edit] your answer to make it clearer and more complete. – G-Man Says 'Reinstate Monica' Jul 22 '22 at 20:38