Skip to content

Commit 3db6767

Browse files
committed
Allow interval to be configurable
1 parent 0f0ae8f commit 3db6767

7 files changed

Lines changed: 49 additions & 7 deletions

File tree

Jenkinsfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pipeline {
281281
-v ${WORKSPACE}:/mnt \
282282
-e AWS_ACCESS_KEY_ID=\"${S3_KEY}\" \
283283
-e AWS_SECRET_ACCESS_KEY=\"${S3_SECRET}\" \
284-
ghcr.io/linuxserver/baseimage-alpine:3 s6-envdir -fn -- /var/run/s6/container_environment /bin/bash -c "\
284+
ghcr.io/linuxserver/baseimage-alpine:3.23 s6-envdir -fn -- /var/run/s6/container_environment /bin/bash -c "\
285285
apk add --no-cache python3 && \
286286
python3 -m venv /lsiopy && \
287287
pip install --no-cache-dir -U pip && \

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ The architectures supported by this image are:
5858

5959
- Go to the [duckdns website](https://duckdns.org/), register your subdomain(s) and retrieve your token.
6060
- Create a container with your subdomain(s) and token. If you own `user.duckdns.org`, you set `SUBDOMAINS=user`. You would NOT set a sub subdomain like `overseerr` from `overseerr.user.ducksdns.org`.
61-
- It will update your IP with the DuckDNS service every 5 minutes (with a random jitter).
61+
- It will update your IP with the DuckDNS service at a configurable interval (default: every 5 minutes, with a random jitter). Use the `UPDATE_INTERVAL` environment variable to customize the update frequency.
6262

6363
## Notice regarding automatic detection
6464

@@ -76,7 +76,7 @@ This image can be run with a read-only container filesystem. For details please
7676
To help you get started creating a container from this image you can either use docker-compose or the docker cli.
7777

7878
>[!NOTE]
79-
>Unless a parameter is flaged as 'optional', it is *mandatory* and a value must be provided.
79+
>Unless a parameter is flagged as 'optional', it is *mandatory* and a value must be provided.
8080
8181
### docker-compose (recommended, [click here for more info](https://docs.linuxserver.io/general/docker-compose))
8282

@@ -94,6 +94,7 @@ services:
9494
- SUBDOMAINS=subdomain1,subdomain2
9595
- TOKEN=token
9696
- UPDATE_IP=ipv4 #optional
97+
- UPDATE_INTERVAL=5m #optional
9798
- LOG_FILE=false #optional
9899
volumes:
99100
- /path/to/duckdns/config:/config #optional
@@ -112,6 +113,7 @@ docker run -d \
112113
-e SUBDOMAINS=subdomain1,subdomain2 \
113114
-e TOKEN=token \
114115
-e UPDATE_IP=ipv4 `#optional` \
116+
-e UPDATE_INTERVAL=5m `#optional` \
115117
-e LOG_FILE=false `#optional` \
116118
-v /path/to/duckdns/config:/config `#optional` \
117119
--restart unless-stopped \
@@ -131,6 +133,7 @@ Containers are configured using parameters passed at runtime (such as those abov
131133
| `-e SUBDOMAINS=subdomain1,subdomain2` | multiple subdomains allowed, comma separated, no spaces, if your domain is user.duckdns.org you put user, not a sub-subdomain |
132134
| `-e TOKEN=token` | DuckDNS token |
133135
| `-e UPDATE_IP=ipv4` | Set to `ipv6` or `ipv4` to update **only** your public IPv4/6 address. Set to `both` to update IPv6 and IPv4 address. This variable makes use of a [third-party service](#notice-regarding-automatic-detection). Omitting this variable uses DuckDNS for detection and only supports IPv4. `both` and `ipv6` modes needs [host networking](#networking-net). |
136+
| `-e UPDATE_INTERVAL=5m` | Set the update interval. Format: `[number][m|h]` where `m` is minutes (5-60) or `h` is hours (1-24). Examples: `5m` (every 5 minutes), `30m` (every 30 minutes), `2h` (every 2 hours). Default is `5m`. |
134137
| `-e LOG_FILE=false` | Set to `true` to log to file (also need to map /config). |
135138
| `-v /config` | Persistent config files. Also set `LOG_FILE=true` to keep address history. |
136139
| `--read-only=true` | Run container with a read-only filesystem. Please [read the docs](https://docs.linuxserver.io/misc/read-only/). |
@@ -299,6 +302,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
299302

300303
## Versions
301304

305+
* **18.02.26:** - Add configurable update interval via UPDATE_INTERVAL environment variable.
302306
* **27.07.25:** - Rebase to Alpine 3.22.
303307
* **27.01.25:** - Rebase to Alpine 3.21.
304308
* **24.06.24:** - Rebase to Alpine 3.20.

readme-vars.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ param_env_vars:
2525
opt_param_usage_include_env: true
2626
opt_param_env_vars:
2727
- {env_var: "UPDATE_IP", env_value: "ipv4", desc: "Set to `ipv6` or `ipv4` to update **only** your public IPv4/6 address. Set to `both` to update IPv6 and IPv4 address. This variable makes use of a [third-party service](#notice-regarding-automatic-detection). Omitting this variable uses DuckDNS for detection and only supports IPv4. `both` and `ipv6` modes needs [host networking](#networking-net).", env_options: ["", "ipv4", "ipv6", "both"]}
28+
- {env_var: "UPDATE_INTERVAL", env_value: "5m", desc: "Set the update interval. Format: `[number][m|h]` where `m` is minutes (5-60) or `h` is hours (1-24). Examples: `5m` (every 5 minutes), `30m` (every 30 minutes), `2h` (every 2 hours). Default is `5m`.", env_options: ["5m", "30m", "1h", "2h"]}
2829
- {env_var: "LOG_FILE", env_value: "false", desc: "Set to `true` to log to file (also need to map /config).", env_options: ["false", "true"]}
2930
opt_param_usage_include_vols: true
3031
opt_param_volumes:
@@ -36,7 +37,7 @@ app_setup_block_enabled: true
3637
app_setup_block: |
3738
- Go to the [duckdns website]({{project_url}}), register your subdomain(s) and retrieve your token.
3839
- Create a container with your subdomain(s) and token. If you own `user.duckdns.org`, you set `SUBDOMAINS=user`. You would NOT set a sub subdomain like `overseerr` from `overseerr.user.ducksdns.org`.
39-
- It will update your IP with the DuckDNS service every 5 minutes (with a random jitter).
40+
- It will update your IP with the DuckDNS service at a configurable interval (default: every 5 minutes, with a random jitter). Use the `UPDATE_INTERVAL` environment variable to customize the update frequency.
4041
4142
## Notice regarding automatic detection
4243
@@ -85,6 +86,7 @@ init_diagram: |
8586
"duckdns:latest" <- Base Images
8687
# changelog
8788
changelogs:
89+
- {date: "18.02.26:", desc: "Add configurable update interval via UPDATE_INTERVAL environment variable."}
8890
- {date: "27.07.25:", desc: "Rebase to Alpine 3.22."}
8991
- {date: "27.01.25:", desc: "Rebase to Alpine 3.21."}
9092
- {date: "24.06.24:", desc: "Rebase to Alpine 3.20."}

root/app/duck.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ if [[ "${LOG_FILE,,}" = "true" ]]; then
77
touch /config/logrotate.status
88
chmod 640 /config/logrotate.status
99
/usr/sbin/logrotate -s /config/logrotate.status /config/logrotate.conf
10+
echo "duck.sh invoked at $(date)" >> "${DUCK_LOG}"
1011
else
1112
DUCK_LOG="/dev/null"
1213
fi

root/defaults/abc.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# min . hour day month weekday command
2+
${MINUTES} ${HOURS} * * * sleep $((60 + $RANDOM % 230)); /app/duck.sh 2>&1

root/etc/crontabs/abc

Lines changed: 0 additions & 2 deletions
This file was deleted.

root/etc/s6-overlay/s6-rc.d/init-duckdns/run

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,47 @@
11
#!/usr/bin/with-contenv bash
22
# shellcheck shell=bash
33

4-
#Check to make sure the subdomain and token are set
4+
# Check to make sure the subdomain and token are set
55
if [ -z "${SUBDOMAINS}" ] || [ -z "${TOKEN}" ]; then
66
echo "Please pass both your subdomain(s) and token as environment variables in your docker run command. See the readme for more details."
77
sleep infinity
88
fi
99

10+
# Render template into real crontab with default interval if not provided
11+
UPDATE_INTERVAL=${UPDATE_INTERVAL:-5m}
12+
if [[ ! "$UPDATE_INTERVAL" =~ ^[0-9]+[mh]?$ ]]; then
13+
echo "Invalid interval format: \"$UPDATE_INTERVAL\", expected format \"[0-9]+[mh]?\""
14+
exit 1
15+
fi
16+
17+
case "$UPDATE_INTERVAL" in
18+
*h)
19+
HOURS=${UPDATE_INTERVAL%h}
20+
if (( HOURS < 1 || HOURS > 24 )); then
21+
echo "Update interval must be between 1-24 hours"
22+
exit 1
23+
fi
24+
HOURS="*/$HOURS"
25+
26+
# We want a single run per selected hour, with the template's jitter handling
27+
# the exact seconds.
28+
MINUTES="0"
29+
;;
30+
*)
31+
MINUTES=${UPDATE_INTERVAL%m}
32+
if (( MINUTES < 5 || MINUTES > 60 )); then
33+
echo "Update interval must be between 5-60 minutes"
34+
exit 1
35+
fi
36+
MINUTES="*/$MINUTES"
37+
38+
HOURS="*"
39+
;;
40+
esac
41+
42+
sed "s|\${MINUTES} \${HOURS}|$MINUTES $HOURS|g" < /defaults/abc.tmpl > /etc/crontabs/abc
43+
chmod 644 /etc/crontabs/abc
44+
1045
if [[ ! -f /config/logrotate.conf ]]; then
1146
cp /defaults/logrotate.conf /config/logrotate.conf
1247
chmod 640 /config/logrotate.conf

0 commit comments

Comments
 (0)