improve daemon shutdown detection

This commit is contained in:
Niko Storni 2018-04-24 14:50:01 -04:00
parent 3bd05692c1
commit f297d47e20

View file

@ -103,15 +103,15 @@ func (s *Sync) FullCycle() error {
shutdownErr := stopDaemonViaSystemd() shutdownErr := stopDaemonViaSystemd()
if shutdownErr != nil { if shutdownErr != nil {
log.Errorf("error shutting down daemon: %v", shutdownErr) log.Errorf("error shutting down daemon: %v", shutdownErr)
log.Errorf("WALLET HAS NOT BEEN MOVED TO THE WALLET BACKUP DIR", shutdownErr) log.Errorf("WALLET HAS NOT BEEN MOVED TO THE WALLET BACKUP DIR")
} else { } else {
// the cli will return long before the daemon effectively stops. we must observe the processes running // the cli will return long before the daemon effectively stops. we must observe the processes running
// before moving the wallet // before moving the wallet
var waitTimeout time.Duration = 180 var waitTimeout time.Duration = 60 * 6
processDeathError := waitForDaemonProcess(waitTimeout) processDeathError := waitForDaemonProcess(waitTimeout)
if processDeathError != nil { if processDeathError != nil {
log.Errorf("error shutdown down daemon: %v", processDeathError) log.Errorf("error shutdown down daemon: %v", processDeathError)
log.Errorf("WALLET HAS NOT BEEN MOVED TO THE WALLET BACKUP DIR", processDeathError) log.Errorf("WALLET HAS NOT BEEN MOVED TO THE WALLET BACKUP DIR")
} else { } else {
walletErr := os.Rename(defaultWalletDir, walletBackupDir) walletErr := os.Rename(defaultWalletDir, walletBackupDir)
if walletErr != nil { if walletErr != nil {
@ -504,7 +504,7 @@ func waitForDaemonProcess(timeout time.Duration) error {
//NOTE : syscall.Signal is not available in Windows //NOTE : syscall.Signal is not available in Windows
err = proc.Signal(syscall.Signal(0)) err = proc.Signal(syscall.Signal(0))
//the process doesn't exist anymore! we're free to go //the process doesn't exist anymore! we're free to go
if err != nil && err == syscall.ESRCH { if err != nil && (err == syscall.ESRCH || err.Error() == "os: process already finished") {
return nil return nil
} }
} }