From 41772f28bdb0b3e9cb96e1f5cea3a185a563b911 Mon Sep 17 00:00:00 2001 From: Daan Selen Date: Thu, 6 Feb 2025 10:52:14 +0100 Subject: [PATCH] Added a SIGTERM trap to the entrypoint script for faster stopping. --- entrypoint.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index dd5eac5..221903e 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,6 +3,14 @@ # Path to the configuration file (exists because of previous function). config_file="/data/wg-dashboard.ini" +trap 'stop_service' SIGTERM + +stop_service() { + echo "[WGDashboard] Stopping WGDashboard..." + ./wgd.sh stop + exit 0 +} + echo "------------------------- START ----------------------------" echo "Starting the WireGuard Dashboard Docker container." @@ -18,7 +26,7 @@ ensure_installation() { if [ ! -d "${WGDASH}/src/db" ]; then ln -s /data/db "${WGDASH}/src/db" fi - + if [ ! -f "${config_file}" ]; then echo "Creating wg-dashboard.ini file" touch "${config_file}" @@ -33,7 +41,7 @@ ensure_installation() { echo "Moving PIP dependency from ephemerality to runtime environment: psutil" mv /usr/lib/python3.12/site-packages/psutil* "${WGDASH}"/src/venv/lib/python3.12/site-packages - + echo "Moving PIP dependency from ephemerality to runtime environment: bcrypt" mv /usr/lib/python3.12/site-packages/bcrypt* "${WGDASH}"/src/venv/lib/python3.12/site-packages @@ -69,7 +77,7 @@ set_envvars() { # Check if the file is empty if [ ! -s "${config_file}" ]; then echo "Config file is empty. Creating [Peers] section." - + # Create [Peers] section with initial values { echo "[Peers]" @@ -89,7 +97,7 @@ set_envvars() { current_dns=$(grep "peer_global_dns = " "${config_file}" | awk '{print $NF}') if [ "${global_dns}" == "$current_dns" ]; then echo "DNS is set correctly, moving on." - + else echo "Changing default DNS..." sed -i "s/^peer_global_dns = .*/peer_global_dns = ${global_dns}/" "${config_file}" @@ -133,7 +141,7 @@ ensure_blocking() { # Find and tail the latest error and access logs if they exist local logdir="${WGDASH}/src/log" - + latestErrLog=$(find "$logdir" -name "error_*.log" -type f -print | sort -r | head -n 1) #latestAccLog=$(find "$logdir" -name "access_*.log" -type f -print | sort -r | head -n 1) # Removed access line due to console spam. @@ -152,4 +160,4 @@ ensure_blocking() { ensure_installation set_envvars start_core -ensure_blocking \ No newline at end of file +ensure_blocking