Disable shutdown event with flag

This commit is contained in:
Daniel
2021-10-11 16:14:44 +02:00
parent 0ff155e7da
commit 879a1745dc

View File

@@ -1,6 +1,7 @@
package core
import (
"flag"
"fmt"
"time"
@@ -27,6 +28,8 @@ var (
restarting = abool.New()
devMode = config.Concurrent.GetAsBool(config.CfgDevModeKey, false)
disableShutdownEvent bool
)
func init() {
@@ -40,6 +43,13 @@ func init() {
nil,
)
flag.BoolVar(
&disableShutdownEvent,
"disable-shutdown-event",
false,
"disable shutdown event to keep app and notifier open when core shuts down",
)
modules.SetGlobalShutdownFn(shutdownHook)
}
@@ -75,18 +85,16 @@ func registerEvents() {
}
func shutdownHook() {
// Don't trigger event in Dev Mode.
if devMode() {
return
}
// Notify everyone of the restart/shutdown.
if restarting.IsNotSet() {
module.TriggerEvent(eventShutdown, nil)
// Only trigger shutdown event if not disabled.
if !disableShutdownEvent {
module.TriggerEvent(eventShutdown, nil)
}
} else {
module.TriggerEvent(eventRestart, nil)
}
// Wait a bit for the event to propagate.
time.Sleep(1 * time.Second)
time.Sleep(100 * time.Millisecond)
}