timer fix?

This commit is contained in:
Lennart J. Kurzweg (Nx2)
2024-06-25 15:11:07 +02:00
parent 2513906a22
commit 6914a99658
2 changed files with 60 additions and 33 deletions

View File

@@ -1,27 +1,56 @@
{ config, pkgs, lib, user, host, ... }:
{ pkgs, lib, user, host, ... }:
lib.mkIf (host == "NxACE")
{
imports = if host == "NxACE" then [
] else [];
config = lib.mkIf (host == "NxACE") {
systemd = {
timers."namecheap-dynamic-dns" = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "2m";
OnUnitActiveSec = "10m";
Unit = "namecheap-dynamic-dns.service";
};
systemd = {
timers."namecheap-dynamic-dns" = {
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "2m";
OnUnitActiveSec = "10m";
Unit = "namecheap-dynamic-dns.service";
};
services."namecheap-dynamic-dns" = {
script = ''
/home/nx2/nx2site/domain/update-namecheap.sh
'';
serviceConfig = {
Type = "oneshot";
User = "nx2";
};
};
services."namecheap-dynamic-dns" =
let
u = pkgs.writeScriptBin "update_namecheap" ''
my_ip=$(curl -s https://ipinfo.io/ip)
dns_ip=$(nslookup nx2.site | grep -E "Address: [0-9]" | cut -c 10-)
fdc="/home/nx2/nx2site/domain/count.txt"
force_update=false
while getopts "f" opt; do
case $opt in
f)
force_update=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done
if [ "$force_update" == true ] || [ "$my_ip" != "$dns_ip" ]; then
count=$(<$fdc)
echo [ $count times ] $(date) from $dns_ip to $my_ip >> /home/nx2/nx2site/domain/updates.log
pw=$(cat /home/nx2/nx2site/domain/pw.txt)
# cat /home/nx2/nx2site/domain/subdomain.list | parallel -j2 "curl -s 'https://dynamicdns.park-your-domain.com/update?host={}&domain=nx2.site&password=$pw&ip=$my_ip'"
curl -s "https://dynamicdns.park-your-domain.com/update?host=@&domain=nx2.site&password=$pw&ip=$my_ip"
curl -s "https://dynamicdns.park-your-domain.com/update?host=*&domain=nx2.site&password=$pw&ip=$my_ip"
echo curl -s "https://dynamicdns.park-your-domain.com/update?host=*&domain=nx2.site&password=$pw&ip=$my_ip"
echo 0 > $fdc
fi
'';
in
{
script = ''
set -eu
${u}/bin/update_namecheap
'';
serviceConfig = {
Type = "oneshot";
User = "nx2";
};
};
};