From 7ac2970d8333959b811b83b4bac832852d0f7676 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Wed, 23 Aug 2023 14:18:43 -0600 Subject: [PATCH] fix warewulf.conf location for wwclient Signed-off-by: Christian Goll --- CHANGELOG.md | 1 + internal/app/wwclient/root.go | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8752c6c6..22fe4306 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -91,6 +91,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 file is create and will executed after the `ignition-disks-ww4.service` has finished. Entries in `/etc/fstab` for every file system are created with the `noauto` option. +- wwclient has now a commandline switch for the location of warewulf.conf ## [4.4.0] 2023-01-18 ### Added diff --git a/internal/app/wwclient/root.go b/internal/app/wwclient/root.go index 5af79840..88df49e1 100644 --- a/internal/app/wwclient/root.go +++ b/internal/app/wwclient/root.go @@ -16,8 +16,8 @@ import ( "github.com/coreos/go-systemd/daemon" "github.com/google/uuid" - "github.com/hpcng/warewulf/internal/pkg/pidfile" warewulfconf "github.com/hpcng/warewulf/internal/pkg/config" + "github.com/hpcng/warewulf/internal/pkg/pidfile" "github.com/hpcng/warewulf/internal/pkg/wwlog" "github.com/spf13/cobra" "github.com/talos-systems/go-smbios/smbios" @@ -31,14 +31,16 @@ var ( RunE: CobraRunE, SilenceUsage: true, } - DebugFlag bool - PIDFile string - Webclient *http.Client + DebugFlag bool + PIDFile string + Webclient *http.Client + WarewulfConfArg string ) func init() { rootCmd.PersistentFlags().BoolVarP(&DebugFlag, "debug", "d", false, "Run with debugging messages enabled.") rootCmd.PersistentFlags().StringVarP(&PIDFile, "pidfile", "p", "/var/run/wwclient.pid", "PIDFile to use") + rootCmd.PersistentFlags().StringVar(&WarewulfConfArg, "warewulfconf", "", "Set the warewulf configuration file") } @@ -48,9 +50,18 @@ func GetRootCommand() *cobra.Command { return rootCmd } -func CobraRunE(cmd *cobra.Command, args []string) error { +func CobraRunE(cmd *cobra.Command, args []string) (err error) { conf := warewulfconf.Get() - + if WarewulfConfArg != "" { + err = conf.Read(WarewulfConfArg) + } else if os.Getenv("WAREWULFCONF") != "" { + err = conf.Read(os.Getenv("WAREWULFCONF")) + } else { + err = conf.Read(warewulfconf.ConfigFile) + } + if err != nil { + return + } pid, err := pidfile.Write(PIDFile) if err != nil && pid == -1 { wwlog.Warn("%v. starting new wwclient", err)