Skip to content

Commit 527e6c4

Browse files
authored
Merge pull request #27 from bcdevtools/imp/early-restart-node-after-dump
imp: restart node right after dumped or before exit due to error
2 parents 79a70d6 + 1244fbd commit 527e6c4

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

cmd/node/dump_snapshot/dump_snapshot.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ func GetDumpSnapshotCmd() *cobra.Command {
119119
defer execCleanup()
120120

121121
var stoppedService bool
122+
123+
defer func() {
124+
if exitWithError && stoppedService {
125+
fmt.Println("INF: restarting service before exit due to error")
126+
ec := utils.LaunchApp("sudo", []string{"systemctl", "restart", serviceName})
127+
if ec != 0 {
128+
utils.PrintlnStdErr("ERR: failed to restart service", serviceName)
129+
}
130+
}
131+
}()
132+
122133
go func() {
123134
time.Sleep(maxDuration)
124135
utils.PrintlnStdErr("ERR: timeout")
@@ -239,6 +250,18 @@ func GetDumpSnapshotCmd() *cobra.Command {
239250
_ = os.Remove(outputFileName)
240251
})
241252

253+
if !noService {
254+
// restart the service
255+
fmt.Println("INF: restarting service")
256+
ec = utils.LaunchApp("sudo", []string{"systemctl", "restart", serviceName})
257+
if ec != 0 {
258+
utils.PrintlnStdErr("ERR: failed to restart service")
259+
exitWithError = true
260+
return
261+
}
262+
time.Sleep(15 * time.Second)
263+
}
264+
242265
fmt.Println("INF: restoring into", dumpHomeDir)
243266
ec = utils.LaunchApp(binary, []string{
244267
"snapshots", "load", outputFileName,
@@ -292,15 +315,6 @@ func GetDumpSnapshotCmd() *cobra.Command {
292315
registeredCleanup = append(registeredCleanup, func() {
293316
_ = launchCmd.Process.Kill()
294317
})
295-
} else {
296-
fmt.Println("INF: restarting service")
297-
ec = utils.LaunchApp("sudo", []string{"systemctl", "restart", serviceName})
298-
if ec != 0 {
299-
utils.PrintlnStdErr("ERR: failed to restart service")
300-
exitWithError = true
301-
return
302-
}
303-
time.Sleep(5 * time.Second)
304318
}
305319

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

0 commit comments

Comments
 (0)