Eine Unterhaltung beginnen

Create Startup/Shutdown script using systemd on Debian

Create Startup/Shutdown script using system on Debian

Prerequistes (placing scripts):

Place the scripts you want to run in the following folder:

/usr/local/bin/

and make them executable:

sudo chmod +x /usr/local/bin/your_script.sh

Create a service file in the location intended for them:

sudo nano /etc/systemd/system/your-service.service

Startup:

[Unit]
Description=Run script at startup after network becomes reachable
After=network.target # example, if you want to load it after everything is ready take: getty.target or after all services are loaded: default.target

[Service]
Type=simple
RemainAfterExit=yes
ExecStartPre=/bin/sleep 10 # lets the system sleep before it starts the command ExecStart=/etc/systemd/system/your_script.sh TimeoutStartSec=0 [Install] WantedBy=default.target

Shutdown:

[Unit]
Description=Run my custom task at shutdown only
DefaultDependencies=no
Before=poweroff.target halt.target shutdown.target


[Service]
Type=simple
ExecStart=/usr/local/bin/my_shutdown_script.sh # or place a command here
TimoutStartSec=0

[Install]
WantedBy=shutdown.target

Helpful Links:

https://www.golinuxcloud.com/beginners-guide-systemd-tutorial-linux/

https://www.golinuxcloud.com/run-script-at-startup-boot-without-cron-linux/

https://wiki.debian.org/systemd

https://www.freedesktop.org/software/systemd/man/systemd.unit.html

Dateien auswählen oder ziehen Sie die Dateien hierher
Hilfreich?
Ja
Nein
  1. Julian Zoelly

  2. Veröffentlicht

Kommentare