Systemctl Utils - LeandroTheDev/arch_linux GitHub Wiki
Variables
Unit
- After=network.target
-
Executes after the internet drivers
- Type=simple
-
Execution type, simple -> no fork the service is considerated as running after execution use for infinite program execution, oneshot -> the service is only finished when the program/script is finished
Services
- User=myuser
-
Will be executed by the user
- WorkingDirectory=/path/to/directory
-
Directroy that will be executed
- Restart=always/on-failure
-
Restart policy (always/on-failure)
- RestartSec=5s
-
Time to restart
Run program after boot
- sudo vim /etc/systemd/system/myscript.service/
[Unit]
Description=This will run after Boot
[Service]
Type=simple
ExecStart=program/location
[Install]
WantedBy=multi-user.target
- systemctl enable myscript.service
Timer execution
- sudo vim /etc/systemd/system/customscript.service
[Unit]
Description=My custom script
[Service]
Type=oneshot
ExecStart=/usr/local/bin/custom_script.sh
- sudo vim /etc/systemd/system/mytimer.timer
Periodic
[Unit]
Description=My custom timer that will exec every 1 hour
[Timer]
OnBootSec=5min
OnUnitActiveSec=1h
Persistent=true
[Install]
WantedBy=timers.target
Calendar
[Unit]
Description=My custom timer that will exec all tuesday 8 pm
[Timer]
OnCalendar=Tue 20:00:00
Persistent=true
[Install]
WantedBy=timers.target
- sudo systemctl enable --now mytimer.timer