changed error handling
This commit is contained in:
parent
23b76f349e
commit
1f41c24001
16
main.go
16
main.go
|
@ -34,8 +34,8 @@ var (
|
||||||
type notifyType string
|
type notifyType string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DaemonStarted notifyType = "READY=1"
|
DaemonStarted =notifyType("READY=1")
|
||||||
DaemonStopping notifyType = "STOPPING=1"
|
DaemonStopping =notifyType("STOPPING=1")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ func CpuTempetureMonitoring(info *Processor, notifier chan<- TempetureChange, ct
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func CpuTempetureScraper(processorCount int, notifier <-chan TempetureChange, ctx context.Context, waiter *sync.WaitGroup) {
|
func CpuTempetureScraper(processorCount int, notifier <-chan TempetureChange,errorChan chan<- error, ctx context.Context, waiter *sync.WaitGroup) {
|
||||||
waiter.Add(1)
|
waiter.Add(1)
|
||||||
defer waiter.Done()
|
defer waiter.Done()
|
||||||
pastFan := make([]int, processorCount)
|
pastFan := make([]int, processorCount)
|
||||||
|
@ -167,7 +167,8 @@ func CpuTempetureScraper(processorCount int, notifier <-chan TempetureChange, ct
|
||||||
)
|
)
|
||||||
cmd := exec.Command("ipmitool", args...)
|
cmd := exec.Command("ipmitool", args...)
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
fmt.Printf(err.Error())
|
errorChan <- err
|
||||||
|
return
|
||||||
}
|
}
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
@ -181,6 +182,7 @@ func main() {
|
||||||
ctx, canceled = context.WithCancel(context.Background())
|
ctx, canceled = context.WithCancel(context.Background())
|
||||||
waiter = &sync.WaitGroup{}
|
waiter = &sync.WaitGroup{}
|
||||||
exitSignal = make(chan os.Signal, 1)
|
exitSignal = make(chan os.Signal, 1)
|
||||||
|
errorChan = make(chan error, 1)
|
||||||
tempetureChange = make(chan TempetureChange)
|
tempetureChange = make(chan TempetureChange)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -188,7 +190,7 @@ func main() {
|
||||||
info := getProcessorInfo(i)
|
info := getProcessorInfo(i)
|
||||||
go CpuTempetureMonitoring(info, tempetureChange, ctx, waiter)
|
go CpuTempetureMonitoring(info, tempetureChange, ctx, waiter)
|
||||||
}
|
}
|
||||||
go CpuTempetureScraper(processorCount, tempetureChange, ctx, waiter)
|
go CpuTempetureScraper(processorCount, tempetureChange,errorChan, ctx, waiter)
|
||||||
defer waiter.Wait()
|
defer waiter.Wait()
|
||||||
signal.Notify(exitSignal, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
|
signal.Notify(exitSignal, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP)
|
||||||
NotifyDaemon(DaemonStarted)
|
NotifyDaemon(DaemonStarted)
|
||||||
|
@ -198,10 +200,12 @@ func main() {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
fmt.Println("Service request to close this application")
|
fmt.Println("Service request to close this application")
|
||||||
return
|
return
|
||||||
|
case err:= <-errorChan:
|
||||||
|
canceled()
|
||||||
|
fmt.Printf("error! %s", error.Error())
|
||||||
case sysSignal := <-exitSignal:
|
case sysSignal := <-exitSignal:
|
||||||
canceled()
|
canceled()
|
||||||
fmt.Printf("SYSCALL! %s", sysSignal.String())
|
fmt.Printf("SYSCALL! %s", sysSignal.String())
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue