Skip to content

Instantly share code, notes, and snippets.

@YouSysAdmin
Created October 28, 2020 07:54
Show Gist options
  • Save YouSysAdmin/ff34854b35d044f636e08f04eaedcf07 to your computer and use it in GitHub Desktop.
Save YouSysAdmin/ff34854b35d044f636e08f04eaedcf07 to your computer and use it in GitHub Desktop.
Systemd - Run before shutdown/reboot
# systemd unit file
# /etc/systemd/system/run-before-shutdown.service
# TimeoutStartSec - set a timeout for your task or set "0" to disable.
# When the timeout is turned off and the task "hangs",
# the process will never be interrupted and the system
# shutdown will stop
# Before - Specify the services before which the task should run
# after add unit file in systemd/system catalogue, "run systemctl daemon-reload"
# and enable new service "systemctl enable run-before-shutdown.service"
[Unit]
Description=My task
DefaultDependencies=no
Before=shutdown.target
[Service]
Type=oneshot
ExecStart=/path_to/script.sh
TimeoutStartSec=0
[Install]
WantedBy=shutdown.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment