add systemd examples
This commit is contained in:
42
active/software_systemd/systemd.md
Normal file
42
active/software_systemd/systemd.md
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
# Systemd
|
||||||
|
|
||||||
|
## Timers
|
||||||
|
|
||||||
|
Basic timer:
|
||||||
|
|
||||||
|
my_service.timer
|
||||||
|
|
||||||
|
```conf
|
||||||
|
[Unit]
|
||||||
|
Description=Run $my_service every hour
|
||||||
|
|
||||||
|
[Timer]
|
||||||
|
OnCalendar=hourly
|
||||||
|
AccuracySec=10min
|
||||||
|
Persistent=true
|
||||||
|
Unit=$my_service.service
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=timers.target
|
||||||
|
```
|
||||||
|
|
||||||
|
my_service.service
|
||||||
|
|
||||||
|
```conf
|
||||||
|
[Unit]
|
||||||
|
Description=Runs some command
|
||||||
|
After=syslog.target network.target auditd.service
|
||||||
|
Wants=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=/usr/bin/command -with -arguments
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
```
|
||||||
|
|
||||||
|
Create an on-the-fly timer (will not survive reboots)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemd-run --user --on-calendar '*:0/1' /bin/sh -c "date >> ~/log.txt"
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user