Skip to content

systemd timer-installation example #38

Open
@Blaimi

Description

I like systemd timers more than cronjobs so I wrote one.

Benefit against cronjob: It runs immediately after boot and from then every 5 minutes. A cronjob runs every fifth minute, i.e. you have to wait 2.5 minutes after boot on average for a initial update.

sudo curl -L https://github.com/FarrowStrange/hetzner-api-dyndns/releases/download/v1.3/dyndns.sh -o /usr/local/bin/hetzner-api-dyndns
sudo chmod +x /usr/local/bin/hetzner-api-dyndns
sudo mkdir -p /etc/hetzner-api-dyndns
cat <<EOF | sudo tee /etc/hetzner-api-dyndns.conf
HETZNER_ZONE_NAME=examle.com
HETZNER_RECORD_NAME=yourhost
HETZNER_RECORD_TYPE=AAAA
HETZNER_AUTH_API_TOKEN=<token>
EOF

cat <<EOF | sudo tee /etc/systemd/system/hetzner-api-dyndns.service
[Unit]
Description=update dyndns entry via hetzner API
After=network-online.target

[Service]
EnvironmentFile=/etc/hetzner-api-dyndns.conf
ExecStart=/usr/local/bin/hetzner-api-dyndns
EOF

cat <<EOF | sudo tee /etc/systemd/system/hetzner-api-dyndns.timer
[Unit]
Description=update dyndns entry via hetzner API every five minutes

[Timer]
Unit=hetzner-api-dyndns.service
# my network takes longer for the IPv6 address
OnBootSec=20
OnUnitActiveSec=5m

[Install]
WantedBy=timers.target
EOF

sudo systemctl daemon-reload
sudo systemctl enable --now hetzner-api-dyndns.timer

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions