New: systemd networking and timer notes

This commit is contained in:
Akemi Izuko 2023-01-06 00:33:30 -07:00
parent c6e69cc769
commit 230174ce1c
No known key found for this signature in database
GPG key ID: 905D444F6A5E4BE4
2 changed files with 78 additions and 0 deletions

View file

@ -0,0 +1,15 @@
# Systemd-networkd
Systemd's networking is effectively composed of 3 parts. The interface configs
in `systemd-networkd`, the DNS resolver? in `systemd-resolved` and the wireless
interface, for our purposes `iwd`
`iwd` is only necessary for wifi
- `/etc/iwd/main.conf`: Disabling passive scanning
- `/var/lib/iwd/`: Per-network profiles, notably for WEP-Enterprise
- `/etc/iwd/main.conf`: Daemon settings
- `/etc/systemd/network`: For networkd stuff, so links and addresses
- `/etc/systemd/system/systemd-networkd-wait-online.service.d`
- `/etc/systemd/resolved.conf`: For resolved
- `/etc/nsswitch.conf`: For nss-mdns
- `/etc/mdns.allow`: Also for nss-mdns, only when not using mdns_minimal

View file

@ -0,0 +1,63 @@
# Systemd Timers
Gen Z's crontab
Generally there are 3 pieces to a timer
- The script being run
- The systemd service defining which script to run
- The systemd timer triggering the service
## Tools
`systemd-analyze calendar` can be very handy at verifying timestamps
```bash
systemd-analyze calendar *-*-* *:10,20:10
```
To find suitable targets for things like `Wants` and `After`, see
`systemd.special(7)`. If you want to check the current status of your targets,
use:
```bash
systemctl list-units --type target --state active
systemctl status network-online.target
```
## Placing files
Scripts should be put in `/usr/local/bin` if they can be run by anyone or
`/usr/local/sbin` if they should only be run by root
Define a `xxx.service` file in `/etc/systemd/system`. Set the timer as one of
its `Wants`. `network.target` may be more appropriate in some cases.
`multi-user.target` is a good default for `WantedBy`
```systemd
[Unit]
Description = Sends current ip address to uni servers
Wants = broadcast_ip.timer
Wants = network.target
After = network.target
[Service]
Type = oneshot
ExecStart = /usr/local/bin/broadcast_ip.sh
[Install]
WantedBy = multi-user.target
```
Now you'll need a timer file. It's easiest to make it have the same name as the
service file and put it in the same `/etc/systemd/system`
```systemd
[Unit]
Description = Sends current ip address to uni servers
Requires = broadcast_ip.service
[Timer]
Unit = broadcast_ip.service
OnCalendar = *-*-* *:15,45:00
[Install]
WantedBy = timers.target
```