Skip to main content
added 58 characters in body
Source Link
Subbeh
  • 430
  • 2
  • 9

I have a systemd service that works for what I want, which is to run a script when the system shuts down. However, this also runs on a reboot which is not what I want.

This is the service file:

[Unit]
Description=Shutdown script
Requires=network.target
Before=shutdownBefore=poweroff.target halt.target
DefaultDependencies=no

[Service]
Type=oneshot
TimeoutSec=5
RemainAfterExit=true
User=sysadm
Group=sysadm
ExecStart=/bin/true
ExecStop=/usr/bin/myscript.sh

[Install]
WantedBy=multi-user.target systemd-halt.service systemd-poweroff.service

Is there any way to make this work for shutdowns only?

I have a systemd service that works for what I want, which is to run a script when the system shuts down. However, this also runs on a reboot which is not what I want.

This is the service file:

[Unit]
Description=Shutdown script
Requires=network.target
Before=shutdown.target
DefaultDependencies=no

[Service]
Type=oneshot
TimeoutSec=5
RemainAfterExit=true
User=sysadm
Group=sysadm
ExecStart=/bin/true
ExecStop=/usr/bin/myscript.sh

[Install]
WantedBy=multi-user.target

Is there any way to make this work for shutdowns only?

I have a systemd service that works for what I want, which is to run a script when the system shuts down. However, this also runs on a reboot which is not what I want.

This is the service file:

[Unit]
Description=Shutdown script
Requires=network.target
Before=poweroff.target halt.target
DefaultDependencies=no

[Service]
Type=oneshot
TimeoutSec=5
RemainAfterExit=true
User=sysadm
Group=sysadm
ExecStart=/bin/true
ExecStop=/usr/bin/myscript.sh

[Install]
WantedBy=multi-user.target systemd-halt.service systemd-poweroff.service

Is there any way to make this work for shutdowns only?

Source Link
Subbeh
  • 430
  • 2
  • 9

Run script on shutdown but not reboot

I have a systemd service that works for what I want, which is to run a script when the system shuts down. However, this also runs on a reboot which is not what I want.

This is the service file:

[Unit]
Description=Shutdown script
Requires=network.target
Before=shutdown.target
DefaultDependencies=no

[Service]
Type=oneshot
TimeoutSec=5
RemainAfterExit=true
User=sysadm
Group=sysadm
ExecStart=/bin/true
ExecStop=/usr/bin/myscript.sh

[Install]
WantedBy=multi-user.target

Is there any way to make this work for shutdowns only?