Skip to content

Instantly share code, notes, and snippets.

@a1994sc
Last active January 30, 2021 15:07
Show Gist options
  • Save a1994sc/b7e848ef93d24151d5652994fe3657be to your computer and use it in GitHub Desktop.
Save a1994sc/b7e848ef93d24151d5652994fe3657be to your computer and use it in GitHub Desktop.
systemd scripts
#!/bin/sh
JSON_LOC="/path/to/file.json"
DNS_ZONE="myzone"
DNS_RECORD="sub.example.com"
TTL=300
CURRENT_RECORD_IP=$(dig +short $DNS_RECORD)
CURRENT_IP=$(curl ifconfig.io/ip)
if [ "$CURRENT_IP" = "$CURRENT_RECORD_IP" ]
then
echo "no changes"
exit 0
fi
#authenticate
gcloud auth activate-service-account --key-file=$JSON_LOC
gcloud dns record-sets transaction start --zone=$DNS_ZONE
gcloud dns record-sets transaction remove --zone=$DNS_ZONE --name=$DNS_RECORD --type=A "$CURRENT_RECORD_IP" --ttl=$TTL
gcloud dns record-sets transaction add --zone=$DNS_ZONE --name=$DNS_RECORD --type=A "$CURRENT_IP" --ttl=$TTL
gcloud dns record-sets transaction execute --zone=$DNS_ZONE
version: "3"
# More info at https://github.com/pi-hole/docker-pi-hole/ and https://docs.pi-hole.net/
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
ports:
- "53:53/tcp"
- "53:53/udp"
- "67:67/udp"
- "80:80/tcp"
- "443:443/tcp"
restart: always
environment:
TZ: 'America/New York'
WEBPASSWORD: '<password>'
# HOSTNAME: "pi-hole"
# Volumes store your data between container upgrades
volumes:
- './etc-pihole/:/etc/pihole/'
- './etc-dnsmasq.d/:/etc/dnsmasq.d/'
# Recommended but not required (DHCP needs NET_ADMIN)
# https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
cap_add:
- NET_ADMIN
restart: unless-stopped
#!/bin/sh
docker-compose down
docker-compose pull
docker-compose up --detach
#Path = /etc/systemd/system/dns_update.service
[Unit]
Description=Script to update Google Cloud DNS records for "my.example.com"
[Service]
Type=simple
ExecStart=/usr/bin/env bash /etc/google-cloud-sdk/scripts/dns-updater
[Install]
WantedBy=multi-user.target
#Path = /etc/systemd/system/conlon-dns_update.timer
[Unit]
Description=Run "conlon-dns_update.service" to update the A record every half hour/
[Timer]
OnCalendar=*-*-* *:00/30:00
Unit=example-dns_update.service
[Install]
WantedBy=multi-user.target
#Path = /etc/systemd/system/pihole_update.service
[Unit]
Description=Script to update pihole docker image.
[Service]
Type=simple
WorkingDirectory=/home/pi/docker/pihole
ExecStart=/usr/bin/env bash /home/pi/docker/pihole/docker_update
[Install]
WantedBy=multi-user.target
#Path = /etc/systemd/system/pihole_update.timer
[Unit]
Description=Run "pihole_update.service" to update pihole image once a day
[Timer]
OnCalendar=daily
Unit=pihole_update.service
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment