Skip to content

Commit 862b6b3

Browse files
committed
Fix Docker entrypoint to pass flags to both cron and one-shot mode
Previously any argument triggered one-shot mode, so --quiet in cron mode was impossible. Now only --run-once triggers one-shot. All other flags (--quiet, --force, etc.) are passed to update.php in both modes.
1 parent 4dc3781 commit 862b6b3

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,13 @@ To run the script once instead of starting the scheduler (e.g., to test your con
100100
docker run --rm -v ./config.php:/app/config.php:ro stecklars/dynamic-dns-netcup-api --run-once
101101
```
102102

103-
You can also pass other flags like `--force` (bypass IP cache) or `--quiet`. One-shot mode is meant for testing and manual runs — for regular use, use the cron mode above (the default) which handles scheduling, caching, and jitter automatically.
103+
One-shot mode is meant for testing and manual runs — for regular use, use the cron mode (the default) which handles scheduling, caching, and jitter automatically.
104+
105+
Script flags like `--force` and `--quiet` can be used in both modes, e.g.:
106+
107+
```bash
108+
docker run --rm -v ./config.php:/app/config.php:ro stecklars/dynamic-dns-netcup-api --run-once --force
109+
```
104110

105111
#### Docker notes
106112
* **"Permission denied" errors on Fedora, RHEL, or openSUSE**: These systems use SELinux, which blocks container access to mounted files even if file permissions look correct. Fix this by adding the `:z` flag to all volume mounts, e.g., `-v ./config.php:/app/config.php:ro,z -v dyndns-data:/app/data:z`. This does not affect NAS systems.

docker-entrypoint.sh

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,22 @@ if (!defined('CACHE_FILE')) {
1010
}
1111
CONFIGEOF
1212

13-
# If arguments are passed, run in one-shot mode instead of starting cron.
14-
# --run-once triggers a single run without extra flags.
15-
# Any other arguments (e.g., --force, --quiet) are passed through to update.php.
16-
if [ "$1" = "--run-once" ]; then
17-
exec php /app/update.php -c /app/config.docker.php
18-
elif [ $# -gt 0 ] && [ "$1" != "cron" ]; then
19-
exec php /app/update.php -c /app/config.docker.php "$@"
13+
# Check for --run-once flag and remove it from the argument list.
14+
# Remaining arguments (e.g., --quiet, --force) are passed to update.php
15+
# in both one-shot and cron mode.
16+
RUN_ONCE=false
17+
ARGS=""
18+
for arg in "$@"; do
19+
if [ "$arg" = "--run-once" ]; then
20+
RUN_ONCE=true
21+
else
22+
ARGS="$ARGS $arg"
23+
fi
24+
done
25+
26+
# One-shot mode: run once and exit.
27+
if [ "$RUN_ONCE" = "true" ]; then
28+
exec php /app/update.php -c /app/config.docker.php $ARGS
2029
fi
2130

2231
# Cron mode (default)
@@ -26,11 +35,11 @@ echo "Starting dynamic DNS client for netcup (cron: $CRON_SCHEDULE)"
2635
echo "Press Ctrl+C or stop the container to exit."
2736

2837
# Run once immediately so the user gets feedback on startup.
29-
php /app/update.php -c /app/config.docker.php
38+
php /app/update.php -c /app/config.docker.php $ARGS
3039

3140
# Set up crontab. Output is redirected to Docker's stdout/stderr
3241
# so that 'docker logs' shows the script's output.
33-
echo "$CRON_SCHEDULE php /app/update.php -c /app/config.docker.php >> /proc/1/fd/1 2>> /proc/1/fd/2" | crontab -
42+
echo "$CRON_SCHEDULE php /app/update.php -c /app/config.docker.php $ARGS >> /proc/1/fd/1 2>> /proc/1/fd/2" | crontab -
3443

3544
# Start crond in the foreground (PID 1).
3645
exec crond -f -l 2

0 commit comments

Comments
 (0)