From 1630fa0213139e0af3579de177b129fd95ad171e Mon Sep 17 00:00:00 2001 From: Tomoki Sugiura Date: Tue, 9 Jan 2024 13:21:18 +0900 Subject: [PATCH 1/2] Remove section for executing resetDell periodically Signed-off-by: Tomoki Sugiura --- pkg/monitor-hw/cmd/dell.go | 33 +-------------------------------- pkg/monitor-hw/cmd/root.go | 9 ++------- 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/pkg/monitor-hw/cmd/dell.go b/pkg/monitor-hw/cmd/dell.go index 5658755..f5f2842 100644 --- a/pkg/monitor-hw/cmd/dell.go +++ b/pkg/monitor-hw/cmd/dell.go @@ -2,10 +2,7 @@ package cmd import ( "context" - "os" - "time" - "github.com/cybozu-go/log" "github.com/cybozu-go/well" ) @@ -13,35 +10,7 @@ func monitorDell(ctx context.Context) error { if err := initDell(ctx); err != nil { return err } - if err := resetDell(ctx); err != nil { - return err - } - - env := well.NewEnvironment(ctx) - env.Go(func(ctx context.Context) error { - for { - select { - case <-time.After(time.Duration(opts.resetInterval) * time.Hour): - case <-ctx.Done(): - return nil - } - - if _, err := os.Stat(opts.noResetFile); err == nil { - // if no-reset file exists, skip reset. - continue - } - - if err := resetDell(ctx); err != nil { - log.Error("failed to reset iDRAC", map[string]interface{}{ - log.FnError: err, - }) - // continue working - } - } - }) - - env.Stop() - return env.Wait() + return resetDell(ctx) } func initDell(ctx context.Context) error { diff --git a/pkg/monitor-hw/cmd/root.go b/pkg/monitor-hw/cmd/root.go index 0bd3065..a08d6cd 100644 --- a/pkg/monitor-hw/cmd/root.go +++ b/pkg/monitor-hw/cmd/root.go @@ -16,15 +16,12 @@ import ( var opts struct { listenAddress string interval int - resetInterval int noResetFile string } const ( - defaultAddress = ":9105" - defaultInterval = 60 - defaultResetInterval = 24 - defaultNoReset = "/var/lib/setup-hw/no-reset" + defaultAddress = ":9105" + defaultInterval = 60 ) // rootCmd represents the base command when called without any subcommands @@ -125,6 +122,4 @@ func Execute() { func init() { rootCmd.Flags().StringVar(&opts.listenAddress, "listen", defaultAddress, "listening address and port number") rootCmd.Flags().IntVar(&opts.interval, "interval", defaultInterval, "interval of collecting metrics in seconds") - rootCmd.Flags().IntVar(&opts.resetInterval, "reset-interval", defaultResetInterval, "interval of resetting iDRAC in hours (dell servers only)") - rootCmd.Flags().StringVar(&opts.noResetFile, "no-reset", defaultNoReset, "path of the no-reset file") } From 4422922d63fa5d1b9216e9b7ea78f388bad9b151 Mon Sep 17 00:00:00 2001 From: Tomoki Sugiura Date: Wed, 10 Jan 2024 10:43:51 +0900 Subject: [PATCH 2/2] Remove monitor go-routines Signed-off-by: Tomoki Sugiura --- pkg/monitor-hw/cmd/dell.go | 6 +++--- pkg/monitor-hw/cmd/qemu.go | 10 ---------- pkg/monitor-hw/cmd/root.go | 13 +++++-------- 3 files changed, 8 insertions(+), 21 deletions(-) delete mode 100644 pkg/monitor-hw/cmd/qemu.go diff --git a/pkg/monitor-hw/cmd/dell.go b/pkg/monitor-hw/cmd/dell.go index f5f2842..a034eb9 100644 --- a/pkg/monitor-hw/cmd/dell.go +++ b/pkg/monitor-hw/cmd/dell.go @@ -6,14 +6,14 @@ import ( "github.com/cybozu-go/well" ) -func monitorDell(ctx context.Context) error { - if err := initDell(ctx); err != nil { +func initDell(ctx context.Context) error { + if err := setupDell(ctx); err != nil { return err } return resetDell(ctx) } -func initDell(ctx context.Context) error { +func setupDell(ctx context.Context) error { if err := well.CommandContext(ctx, "/usr/libexec/instsvcdrv-helper", "start").Run(); err != nil { return err } diff --git a/pkg/monitor-hw/cmd/qemu.go b/pkg/monitor-hw/cmd/qemu.go deleted file mode 100644 index 2c59ca7..0000000 --- a/pkg/monitor-hw/cmd/qemu.go +++ /dev/null @@ -1,10 +0,0 @@ -package cmd - -import ( - "context" -) - -func monitorQEMU(ctx context.Context) error { - <-ctx.Done() - return nil -} diff --git a/pkg/monitor-hw/cmd/root.go b/pkg/monitor-hw/cmd/root.go index a08d6cd..86c5ec1 100644 --- a/pkg/monitor-hw/cmd/root.go +++ b/pkg/monitor-hw/cmd/root.go @@ -51,12 +51,10 @@ var rootCmd = &cobra.Command{ return err } - var monitor func(context.Context) error var client redfish.Client var ruleGetter redfish.RuleGetter switch vendor { case lib.QEMU: - monitor = monitorQEMU client = redfish.NewMockClient(redfish.DummyRedfishFile) ruleFile := "qemu.yml" rule, ok := redfish.Rules[ruleFile] @@ -68,7 +66,9 @@ var rootCmd = &cobra.Command{ } case lib.Dell: - monitor = monitorDell + if err := initDell(cmd.Context()); err != nil { + return err + } cc := &redfish.ClientConfig{ AddressConfig: ac, UserConfig: uc, @@ -96,15 +96,12 @@ var rootCmd = &cobra.Command{ return errors.New("unsupported vendor hardware") } - err = startExporter(ruleGetter, client) - if err != nil { + if err := startExporter(ruleGetter, client); err != nil { return err } - well.Go(monitor) well.Stop() - err = well.Wait() - if err != nil && !well.IsSignaled(err) { + if err := well.Wait(); err != nil && !well.IsSignaled(err) { return err } return nil