diff --git a/pkg/monitor-hw/cmd/dell.go b/pkg/monitor-hw/cmd/dell.go index 5658755..a034eb9 100644 --- a/pkg/monitor-hw/cmd/dell.go +++ b/pkg/monitor-hw/cmd/dell.go @@ -2,49 +2,18 @@ package cmd import ( "context" - "os" - "time" - "github.com/cybozu-go/log" "github.com/cybozu-go/well" ) -func monitorDell(ctx context.Context) error { - if err := initDell(ctx); err != nil { - return err - } - if err := resetDell(ctx); err != nil { +func initDell(ctx context.Context) error { + if err := setupDell(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 { +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 0bd3065..86c5ec1 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 @@ -54,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] @@ -71,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, @@ -99,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 @@ -125,6 +119,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") }