Skip to content

Commit

Permalink
Add default path for config file
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
julianbrost committed Jun 21, 2024
1 parent 7229ee2 commit bc3910f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/...

Expand Down
7 changes: 1 addition & 6 deletions cmd/icinga-notifications/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion internal/paths.go
Original file line number Diff line number Diff line change
@@ -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"
)

0 comments on commit bc3910f

Please sign in to comment.