From 2ab1f7dc525a1d91640aef19248a43971da8c352 Mon Sep 17 00:00:00 2001 From: Hector Date: Sun, 29 Aug 2021 18:36:27 +0100 Subject: [PATCH] feat: support reading fail2ban socket in docker Update the docker container to support mounting the fail2ban server socket and pointing the exporter at it. This allows the exporter to interact with the socket from within the container. The entire `/var/run` folder is mounted instead of just the socket file to correctly handle fail2ban restarts (where the file will be deleted). --- docker/run.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docker/run.sh b/docker/run.sh index 667158d..0739997 100644 --- a/docker/run.sh +++ b/docker/run.sh @@ -3,7 +3,19 @@ # Print version to logs for debugging purposes /app/fail2ban-prometheus-exporter -version +db_path=/app/fail2ban.sqlite3 +socket_path=/var/run/fail2ban/fail2ban.sock + +# Blank out the file paths if they do not exist - a hacky way to only use these files if they were mounted into the container. +if [ ! -f "$db_path" ]; then + db_path="" +fi +if [ ! -S "$socket_path" ]; then + socket_path="" +fi + # Start the exporter (use exec to support graceful shutdown) # Inspired by: https://akomljen.com/stopping-docker-containers-gracefully/ exec /app/fail2ban-prometheus-exporter \ - -db /app/fail2ban.sqlite3 + -db "$db_path" \ + -socket "$socket_path"