-
-
Save tsak/ab261f4f6974a5e26471628cc307d280 to your computer and use it in GitHub Desktop.
Run DDNS updater as a systemd service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RESOLVER_ADDRESS=1.1.1.1:53 | |
BACKUP_PERIOD=24h | |
LISTENING_ADDRESS=:8092 | |
DATADIR=data | |
BACKUP_DIRECTORY=backups | |
TZ=Europe/London |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Build ddns-updater (optional: pass release tag, e.g. v2.6.0) | |
( | |
cd src | |
if [[ -n "$1" ]]; then | |
git fetch | |
git checkout "$1" | |
fi | |
go build -o ../ddns-updater cmd/updater/main.go | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Update DNS records periodically | |
After=network.target | |
Wants=network-online.target | |
[Service] | |
Restart=always | |
Type=simple | |
ExecStart=/home/ddns-updater/ddns-updater | |
WorkingDirectory=/home/ddns-updater | |
User=ddns-updater | |
Group=ddns-updater | |
EnvironmentFile=/home/ddns-updater/.env | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Add ddns-updater user | |
sudo adduser ddns-updater | |
# Create data and backups directory | |
sudo mkdir /home/ddns-updater/{data,backups} | |
sudo touch /home/ddns-updater/data/config.json | |
sudo cp {.env,build.sh} /home/ddns-updater/ | |
sudo chown -R ddns-updater:ddns-updater /home/ddns-updater/{data,backups,.env} | |
# Become ddns-updater user | |
sudo su - ddns-updater | |
# Clone source code | |
git clone https://github.com/qdm12/ddns-updater.git src | |
# Build version 2.6.0 | |
./build.sh v2.6.0 | |
# Test that it works | |
export $(cat .env | xargs) | |
./ddns-updater | |
# Go back to originating user | |
logout | |
# Create systemd service | |
sudo cp ddns-updater.service /etc/systemd/system/ | |
sudo systemctl start ddns-updater.service | |
sudo systemctl enable ddns-updater.service | |
# Final check | |
sudo journalctl -u ddns-updater.service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment