I want to run daily desktop backups before shutting-down for the night, which means I don’t want them to run before reboot, only before shutdown. But that’s not what’s happening:
There seems to be an argument about conflicts=XXXXX.target That second article you listed has the following reply:
From reading the answers here there seems to be a lot misunderstanding about how systemd works. Firstly don’t use conflicts to exclude a target. It is ment to keep to conflicting services from being run at the same time.
If a unit has a Conflicts= setting on another unit, starting the former will stop the latter and vice versa.
Unit means a .service file ment to launch perticular service not a target to be reach. In other-words Conflicts=reboot.target is meaningless at best and at worst it will prevent you from rebooting. Don’t do this. It does not mean don’t run this on reboot. It means abort either this service or the reboot.target depending on timing and how systemd interprets this erroneous use of conflicts.
So did you have the chance and actually try this on your system? How did it work out / what behaviour did you observe?
I have a similar idea on my to-do-list and your discussion was ringing a bell for me…
I think you’ve mixed up some of the stuff here, basically your unit file is “starting” every time you boot, then stopping via your command no matter how its powered off. The Before=poweroff.target is only saying “this service should be started before a normal poweroff begins”.
Also reboot.target and poweroff.target are mutually exclusive, but they both depend on shutdown.target.
I think what might work (completely untested) would be to set the unit’s WantedBy=poweroff.target, as that would make the unit activate and immediately deactivate on normal poweroff (not reboot) only.
Some more stuff to note:
If you have networking issues, you may need to try something like After=network-online.target, maybe in combination with a similar Requires, instead.