From 675ec831b98842c23393e088a8971c045537642b Mon Sep 17 00:00:00 2001 From: torms <8841885+torms@users.noreply.github.com> Date: Sun, 1 Nov 2026 01:24:53 +0400 Subject: [PATCH] feat(docker): run drop-in scripts from /data/custom-init.d at startup (#1401) Allows users to install additional packages or apply custom setup by placing scripts in /data/custom-init.d, executed in alphabetical order before WGDashboard starts. --- docker/README.md | 15 +++++++++++++++ docker/entrypoint.sh | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/docker/README.md b/docker/README.md index 186c172f..34e3f573 100644 --- a/docker/README.md +++ b/docker/README.md @@ -121,6 +121,20 @@ Updating the WGDashboard container should be through 'The Docker Way' - by pulli --- +## 🧩 Custom Startup Scripts + +Every file placed in `/data/custom-init.d/` is executed with `bash` at container startup, in alphabetical order, right before WGDashboard starts. A failing script is logged but does not stop the container. + +This is useful for installing additional packages, for example `/data/custom-init.d/apk-add`: +```bash +apk update > /dev/null 2>&1 +apk add --no-cache util-linux openssh-client > /dev/null 2>&1 +``` + +> 📁 When using a Docker volume for `/data`, you can also bind-mount the directory directly, e.g. `./custom-init.d:/data/custom-init.d:ro`. + +--- + ## 🔐 Port Forwarding Note When using multiple WireGuard interfaces, remember to **open their respective ports** on the host. @@ -202,6 +216,7 @@ ENTRYPOINT ["/bin/bash", "/entrypoint.sh"] - **`ensure_installation`**: Sets up the app, database, and Python environment. - **`set_envvars`**: Writes `wg-dashboard.ini` and applies environment variables. +- **`run_custom_init`**: Runs user scripts from `/data/custom-init.d/`. - **`start_core`**: Starts the main WGDashboard service. - **`ensure_blocking`**: Tails the error log to keep the container process alive. diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index fe2d2dff..41eac98e 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -258,6 +258,24 @@ set_envvars() { done } +# Run user-provided drop-in scripts, e.g. to install additional packages +run_custom_init() { + local init_dir="/data/custom-init.d" + + [[ -d "$init_dir" ]] || return 0 + + printf "\n------------------ RUNNING CUSTOM SCRIPTS ------------------\n" + + for script in "$init_dir"/*; do + [[ -f "$script" ]] || continue + + echo "Running custom script: ${script}" + if ! bash "$script"; then + echo "Custom script ${script} exited with an error, continuing." + fi + done +} + # Start service and monitor logs start_and_monitor() { printf "\n---------------------- STARTING CORE -----------------------\n" @@ -331,4 +349,5 @@ start_and_monitor() { # Main execution flow ensure_installation set_envvars +run_custom_init start_and_monitor