Add systemd setup docs

I had to set this up tonight, so I figured I'd share
This commit is contained in:
Connor Kennedy
2020-01-28 22:29:56 -06:00
committed by GitHub
parent 7e0b2cb992
commit bfe926863c

View File

@ -157,5 +157,62 @@ And once you can successfully run `pihole-cloudsync --pull` from the command lin
**NOTE:** On Raspian, the script won't execute via cron without the `sudo` command (as shown above). If you're having trouble getting the script to run unattended on Raspian, try including `sudo` in the cron command.
## Automating with systemd
pihole-cloudsync pulls can be automated fairly easily with systemd, given your distro runs it. Once you can successfully run `pihole-cloudsync --push` from the command line on your primary Pi-Hole, you may proceed with systemd setup. There are three files you must install in order to ensure a stable and non-intrusve update process: The _.service_, the _.timer_, and the _.slice_.
### Quick Start
1. Copy the each of the three unit files in the "Details" section below into `/etc/systemd/system` on your machine
2. Tell systemd we changed its configuration files: `systemctl daemon-reload`
3. Enable and start the service/timer
```bash
# Enable the relevant configs
systemctl enable pihole-cloudsync-update.service
systemctl enable pihole-cloudsync-update.timer
# Start the timer
systemctl start pihole-cloudsync-update.timer
```
### Details
1. **.service** - `/etc/systemd/system/pihole-cloudsync-update.service` - The core service file. Configured as a 'oneshot' in order to be run via a [systemd timer](https://wiki.archlinux.org/index.php/Systemd/Timers).
```ini
[Unit]
Description=PiHole Cloud Sync Data Puller service
Wants=pihole-cloudsync-update.timer
[Service]
Type=oneshot
ExecStart=/usr/local/bin/pihole-cloudsync --pull
Slice=pihole-cloudsync-update.slice
[Install]
WantedBy=multi-user.target
```
2. **.timer** - `/etc/systemd/system/pihole-cloudsync-update.timer` - The timer file. Determines when the _.service_ file is executed. Systemd timers are highly flexible and can be executed under a viriety of timed and trigger-based circumstances. The [ArchLinux systemd/Timer documentation](https://wiki.archlinux.org/index.php/Systemd/Timers) are some of the best around. See their [examples](https://wiki.archlinux.org/index.php/Systemd/Timers#Examples) for many ways to configure this systemd unit
```ini
[Unit]
Description=PiHole Cloud Synd Data Puller timer
Requires=pihole-cloudsync-update.service
[Timer]
Unit=pihole-cloudsync-update.service
OnBootSec=15
OnUnitActiveSec=1h
[Install]
WantedBy=timers.target
```
3. **.slice** - `/etc/systemd/system/pihole-cloudsync-update.slice` - The slice file. Determines how much of the total system resources this service is allowed to consume. Since PiHole is a DNS server and we humans like the internet to be as snappy as possible, this is done to ensure that there woll always be _plenty_ of room for the PiHole sevice to operate answer queries without being obstructed by updates. If you'd like to know more about systemd slices, check out [this wiki page](https://wikitech.wikimedia.org/wiki/Systemd_resource_control) for details.
```ini
[Unit]
Description=PiHole Cloud Sync Puller resource limiter slice
Before=slices.target
[Slice]
CPUQuota=50%
```
# Disclaimer
You are totally responsible for anything this script does to your system. Whether it launches a nice game of Tic Tac Toe or global thermonuclear war, you're on your own. :)