From bc3910f0347c1cfaad6f94f762bf21e8351d4718 Mon Sep 17 00:00:00 2001 From: Julian Brost Date: Thu, 20 Jun 2024 13:32:01 +0200 Subject: [PATCH] Add default path for config file Previously, the path to the config file had to be passed on the command line. This commit adds a sensible default so that this is no longer necessary. As the mechanism for setting the channel plugin dir based on libexecdir from the Makefile is already there, the same was used for sysconfdir, even though that should always be /etc for our packaging needs. --- Dockerfile | 2 +- Makefile | 2 +- cmd/icinga-notifications/main.go | 7 +------ internal/paths.go | 3 ++- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index c90f9385..086897bb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,4 +23,4 @@ RUN adduser -u 1000 -H -D -G $username $username USER $username EXPOSE 5680 -CMD ["/usr/sbin/icinga-notifications", "--config", "/etc/icinga-notifications/config.yml"] +CMD ["/usr/sbin/icinga-notifications"] diff --git a/Makefile b/Makefile index 3e7201c6..e41bbe51 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ all: mkdir -p build go build \ -o build/ \ - -ldflags "-X '$(pkg).LibExecDir=$(libexecdir)'" \ + -ldflags "-X '$(pkg).LibExecDir=$(libexecdir)' -X '$(pkg).SysConfDir=$(sysconfdir)'" \ ./cmd/icinga-notifications go build -o build/channel/ ./cmd/channel/... diff --git a/cmd/icinga-notifications/main.go b/cmd/icinga-notifications/main.go index 23d0bfa7..3dea365f 100644 --- a/cmd/icinga-notifications/main.go +++ b/cmd/icinga-notifications/main.go @@ -26,7 +26,7 @@ func main() { var configPath string var showVersion bool - flag.StringVar(&configPath, "config", "", "path to config file") + flag.StringVar(&configPath, "config", internal.SysConfDir+"/icinga-notifications/config.yml", "path to config file") flag.BoolVar(&showVersion, "version", false, "print version") flag.Parse() @@ -43,11 +43,6 @@ func main() { return } - if configPath == "" { - _, _ = fmt.Fprintln(os.Stderr, "missing -config flag") - os.Exit(1) - } - err := daemon.LoadConfig(configPath) if err != nil { _, _ = fmt.Fprintln(os.Stderr, "cannot load config:", err) diff --git a/internal/paths.go b/internal/paths.go index d7076f71..01f2681c 100644 --- a/internal/paths.go +++ b/internal/paths.go @@ -1,6 +1,7 @@ package internal -// This variable exists to allow overwriting the path using `go build -ldflags "-X ...", see Makefile. +// These variables exist to allow overwriting the paths using `go build -ldflags "-X ...", see Makefile. var ( LibExecDir = "/usr/libexec" + SysConfDir = "/etc" )