Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions cmd/node/dump_snapshot/dump_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ func GetDumpSnapshotCmd() *cobra.Command {
defer execCleanup()

var stoppedService bool

defer func() {
if exitWithError && stoppedService {
fmt.Println("INF: restarting service before exit due to error")
ec := utils.LaunchApp("sudo", []string{"systemctl", "restart", serviceName})
if ec != 0 {
utils.PrintlnStdErr("ERR: failed to restart service", serviceName)
}
}
}()

go func() {
time.Sleep(maxDuration)
utils.PrintlnStdErr("ERR: timeout")
Expand Down Expand Up @@ -239,6 +250,18 @@ func GetDumpSnapshotCmd() *cobra.Command {
_ = os.Remove(outputFileName)
})

if !noService {
// restart the service
fmt.Println("INF: restarting service")
ec = utils.LaunchApp("sudo", []string{"systemctl", "restart", serviceName})
if ec != 0 {
utils.PrintlnStdErr("ERR: failed to restart service")
exitWithError = true
return
}
time.Sleep(15 * time.Second)
}

fmt.Println("INF: restoring into", dumpHomeDir)
ec = utils.LaunchApp(binary, []string{
"snapshots", "load", outputFileName,
Expand Down Expand Up @@ -292,15 +315,6 @@ func GetDumpSnapshotCmd() *cobra.Command {
registeredCleanup = append(registeredCleanup, func() {
_ = launchCmd.Process.Kill()
})
} else {
fmt.Println("INF: restarting service")
ec = utils.LaunchApp("sudo", []string{"systemctl", "restart", serviceName})
if ec != 0 {
utils.PrintlnStdErr("ERR: failed to restart service")
exitWithError = true
return
}
time.Sleep(5 * time.Second)
}

rpc, err := types.ReadNodeRpcFromConfigToml(path.Join(nodeHomeDirectory, "config", "config.toml"))
Expand Down