fix(processor): recovery process can be ended in time when the watchdog received stop command.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"Watchdog_Linux-systemd/postLog"
|
||||
"Watchdog_Linux-systemd/global"
|
||||
)
|
||||
|
||||
type ServiceStatusChecker func(serviceName string) bool
|
||||
@@ -18,19 +19,21 @@ func HandleErrorProcess(serviceName string, isServiceRunning ServiceStatusChecke
|
||||
}
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
serviceControl.RetryCount++
|
||||
postLog.Debug(fmt.Sprintf("[HandleErrorProcess] Try to restart service '%s', retry count: %d", serviceName, serviceControl.RetryCount))
|
||||
cmd := exec.Command("systemctl", "restart", serviceName)
|
||||
err := cmd.Run()
|
||||
if err == nil {
|
||||
if isServiceRunning != nil && isServiceRunning(serviceName) {
|
||||
return nil
|
||||
if global.Monitors[serviceName].Recovery { // Only recovery process is started
|
||||
serviceControl.RetryCount++
|
||||
postLog.Debug(fmt.Sprintf("[HandleErrorProcess] Try to restart service '%s', retry count: %d", serviceName, serviceControl.RetryCount))
|
||||
cmd := exec.Command("systemctl", "restart", serviceName)
|
||||
err := cmd.Run()
|
||||
if err == nil {
|
||||
if isServiceRunning != nil && isServiceRunning(serviceName) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Duration(i+1) * time.Second)
|
||||
}
|
||||
time.Sleep(time.Duration(i+1) * time.Second)
|
||||
}
|
||||
serviceControl.ErrorType = "restart"
|
||||
serviceControl.ErrorMsg = fmt.Sprintf("Failed to recover service '%s', retry count: %d", serviceName, serviceControl.RetryCount)
|
||||
serviceControl.ErrorTime = time.Now()
|
||||
return fmt.Errorf(serviceControl.ErrorMsg)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user