From 93da909b0ad2d4516ac5a23e742561fe8f240b9e Mon Sep 17 00:00:00 2001 From: Hector Date: Mon, 31 Jan 2022 22:51:13 +0000 Subject: [PATCH] fix: use correct flag in dockerfile (#18) Update the Dockerfile entrypoint script to use the correct version flag syntax. The flag now requires two dashes instead of one. The syntax for the texfile collector has also change, and the script was updated accordingly. Fix incorrect order of variable assignment when parsing CLI flags. --- docker/run.sh | 21 +++++++++++---------- src/cfg/cfg.go | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docker/run.sh b/docker/run.sh index 36ade9e..4fe96f0 100644 --- a/docker/run.sh +++ b/docker/run.sh @@ -1,20 +1,21 @@ #/bin/sh # Print version to logs for debugging purposes -/app/fail2ban-prometheus-exporter -version +/app/fail2ban-prometheus-exporter --version socket_path=/var/run/fail2ban/fail2ban.sock textfile_dir=/app/textfile/ textfile_enabled=false -# Enable textfile metrics if the folder exists (i.e. was mounted by docker) -if [ -d $textfile_dir ]; then - textfile_enabled=true -fi - # Start the exporter (use exec to support graceful shutdown) # Inspired by: https://akomljen.com/stopping-docker-containers-gracefully/ -exec /app/fail2ban-prometheus-exporter \ - --socket "$socket_path" \ - --collector.textfile=$textfile_enabled \ - --collector.textfile.directory="$textfile_dir" +# Enable textfile metrics if the folder exists (i.e. was mounted by docker) +if [ -d $textfile_dir ]; then + exec /app/fail2ban-prometheus-exporter \ + --socket "$socket_path" \ + --collector.textfile \ + --collector.textfile.directory "$textfile_dir" +else + exec /app/fail2ban-prometheus-exporter \ + --socket "$socket_path" +fi diff --git a/src/cfg/cfg.go b/src/cfg/cfg.go index c71b360..76ad918 100644 --- a/src/cfg/cfg.go +++ b/src/cfg/cfg.go @@ -81,6 +81,8 @@ func readParamsFromCli(settings *AppSettings) { Envar(basicAuthPassEnvName). String() + kingpin.Parse() + settings.VersionMode = *versionMode settings.MetricsPort = *port settings.MetricsAddress = *address @@ -88,8 +90,6 @@ func readParamsFromCli(settings *AppSettings) { settings.FileCollectorEnabled = *fileCollectorEnabled settings.FileCollectorPath = *fileCollectorPath settings.setBasicAuthValues(*rawBasicAuthUsername, *rawBasicAuthPassword) - - kingpin.Parse() } func (settings *AppSettings) setBasicAuthValues(rawUsername, rawPassword string) {