Added a background process for updating the DB

This commit is contained in:
2026-01-11 19:46:40 +01:00
parent 41a4a96075
commit 54abb99607
3 changed files with 9 additions and 1 deletions

38
Docker/entrypoint.sh Normal file
View File

@@ -0,0 +1,38 @@
#!/bin/sh
set -e
# Default to 1600 if not provided
PUID="${PUID:-1600}"
PGID="${PGID:-1600}"
USER="${USER:-apiusr}"
GROUP="${USER:-apiusr}"
CHOWNPATH="/netflowParser"
# Create group if missing
if ! getent group "$GROUP" >/dev/null 2>&1; then
addgroup -g "$PGID" "$GROUP"
fi
# Create user if missing
if ! id -u "$USER" >/dev/null 2>&1; then
adduser -D -u "$PUID" -G "$GROUP" "$USER"
fi
# Download IP2Location database
if [[ -n "$IP2LOC_TOKEN" ]]; then
wget -O "$CHOWNPATH"/IP2LOCATION-LITE-DB9.BIN "https://www.ip2location.com/download/?token="$IP2LOC_TOKEN"&file=DB9LITEBIN"
fi
# Fix permissions (only do this on /app/API)
chown -R "$PUID:$PGID" "$CHOWNPATH"
# Create an updater process
(
while true; do
sleep 12h
su-exec "$PUID:$PGID" "/bin/sh" "$CHOWNPATH"/updateIP2Lbin.sh || true
done
) &
# Drop privileges & run command
exec su-exec "$PUID:$PGID" "$@"