Skip to content

Commit

Permalink
Allow setting libexecdir (/usr/libexec) from build flags
Browse files Browse the repository at this point in the history
This allows building packages with different values of libexecdir with the
daemon binary automatically adapting the channel plugin dir to it, i.e. so
there is no need to specify it in the config file.

This is relevant for Suse where %{_libexecdir} expands to /usr/lib instead.
  • Loading branch information
julianbrost committed Jun 20, 2024
1 parent 63382d2 commit bcba629
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ libexecdir = $(prefix)/libexec
datadir = $(prefix)/share
sysconfdir = /etc

all: pkg = github.com/icinga/icinga-notifications/internal
all:
mkdir -p build
go build -o build/ ./cmd/icinga-notifications
go build \
-o build/ \
-ldflags "-X '$(pkg).LibExecDir=$(libexecdir)'" \
./cmd/icinga-notifications
go build -o build/channel/ ./cmd/channel/...

test:
Expand Down
2 changes: 1 addition & 1 deletion config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#debug-password: "put-something-secret-here"

icingaweb2-url: http://localhost/icingaweb2/
channel-plugin-dir: /usr/libexec/icinga-notifications/channel
#channel-plugin-dir: /usr/libexec/icinga-notifications/channel
api-timeout: 1m

database:
Expand Down
13 changes: 12 additions & 1 deletion internal/daemon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,31 @@ import (
"github.com/goccy/go-yaml"
"github.com/icinga/icinga-go-library/database"
"github.com/icinga/icinga-go-library/logging"
"github.com/icinga/icinga-notifications/internal"
"os"
"time"
)

type ConfigFile struct {
Listen string `yaml:"listen" default:"localhost:5680"`
DebugPassword string `yaml:"debug-password"`
ChannelPluginDir string `yaml:"channel-plugin-dir" default:"/usr/libexec/icinga-notifications/channel"`
ChannelPluginDir string `yaml:"channel-plugin-dir"`
ApiTimeout time.Duration `yaml:"api-timeout" default:"1m"`
Icingaweb2URL string `yaml:"icingaweb2-url"`
Database database.Config `yaml:"database"`
Logging logging.Config `yaml:"logging"`
}

// SetDefaults implements the defaults.Setter interface.
func (c *ConfigFile) SetDefaults() {
if defaults.CanUpdate(c.ChannelPluginDir) {
c.ChannelPluginDir = internal.LibExecDir + "/icinga-notifications/channel"
}
}

// Assert interface compliance.
var _ defaults.Setter = (*ConfigFile)(nil)

// config holds the configuration state as a singleton. It is used from LoadConfig and Config
var config *ConfigFile

Expand Down
6 changes: 6 additions & 0 deletions internal/paths.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package internal

// This variable exists to allow overwriting the path using `go build -ldflags "-X ...", see Makefile.
var (
LibExecDir = "/usr/libexec"
)

0 comments on commit bcba629

Please sign in to comment.