Skip to content

Commit

Permalink
Merge pull request #101 from cybozu-go/remove-tick-reset
Browse files Browse the repository at this point in the history
Remove section for executing `resetDell` periodically
  • Loading branch information
chez-shanpu committed Jan 11, 2024
2 parents 0dfef10 + 4422922 commit f6b88d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 60 deletions.
39 changes: 4 additions & 35 deletions pkg/monitor-hw/cmd/dell.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 0 additions & 10 deletions pkg/monitor-hw/cmd/qemu.go

This file was deleted.

22 changes: 7 additions & 15 deletions pkg/monitor-hw/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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")
}

0 comments on commit f6b88d0

Please sign in to comment.