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.
Here is example of a currently setup unit (aka .service file) that runs only on shutdown not reboot:
[Unit]
Description=Play sound
DefaultDependencies=no
Before=poweroff.target halt.target
[Service]
ExecStart=/usr/local/bin/playsound.sh
ExecStop=/usr/local/bin/playsound.sh
Type=oneshot
RemainAfterExit=yes
[Install]
WantedBy=poweroff.target halt.target
poweroff.target is equivalent to the old systemv run level0 which is only reached at shutdown. halt.target is an alternate shutdown path used by systemd also not reachable by reboot. The install section tells systemd to add this service to the list that must be completed before poweroff.target
or halt.target
will be considered reached.
This service is installed and running on my system.
/etc/systemd/system/
. The/usr/lib/systemd/system/
directory is meant to be used for system-provided scripts.