@@ -583,6 +583,24 @@ func main() {
583583
584584 nodeConfig := createGlobalConfig ()
585585 currentNode := setupConsensusAndNode (nodeConfig )
586+
587+ // Prepare for graceful shutdown from os signals
588+ osSignal := make (chan os.Signal )
589+ signal .Notify (osSignal , os .Interrupt , syscall .SIGTERM )
590+ go func () {
591+ for {
592+ select {
593+ case sig := <- osSignal :
594+ if sig == syscall .SIGTERM || sig == os .Interrupt {
595+ msg := "Got %s signal. Gracefully shutting down...\n "
596+ utils .Logger ().Printf (msg , sig )
597+ fmt .Printf (msg , sig )
598+ currentNode .ShutDown ()
599+ }
600+ }
601+ }
602+ }()
603+
586604 //setup state syncing and beacon syncing frequency
587605 currentNode .SetSyncFreq (* syncFreq )
588606 currentNode .SetBeaconSyncFreq (* beaconSyncFreq )
@@ -654,25 +672,6 @@ func main() {
654672 if currentNode .NodeConfig .GetMetricsFlag () {
655673 go currentNode .CollectMetrics ()
656674 }
657- // Prepare for graceful shutdown from os signals
658- osSignal := make (chan os.Signal )
659- signal .Notify (osSignal , os .Interrupt , os .Kill , syscall .SIGTERM )
660- go func () {
661- for {
662- select {
663- case sig := <- osSignal :
664- if sig == os .Kill || sig == syscall .SIGTERM {
665- fmt .Printf ("Got %s signal. Gracefully shutting down...\n " , sig )
666- currentNode .ShutDown ()
667- }
668- if sig == os .Interrupt {
669- fmt .Printf ("Got %s signal. Dumping state to DB...\n " , sig )
670- currentNode .Blockchain ().Stop ()
671- currentNode .Beaconchain ().Stop ()
672- }
673- }
674- }
675- }()
676675
677676 currentNode .StartServer ()
678677}
0 commit comments