Added a SIGTERM trap to the entrypoint script for faster stopping.

This commit is contained in:
Daan Selen 2025-02-06 10:52:14 +01:00
parent 393dac1c99
commit 41772f28bd

View File

@ -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
ensure_blocking