graceful exit on SIGTERM (#2178)
Much easier than convincing all users to change the default signal in their service definition file to SIGINT.
This commit is contained in:
parent
14c5d6db1e
commit
9daf6be73c
|
@ -9,6 +9,7 @@ import
|
|||
# Standard library
|
||||
std/[os, tables, strutils, strformat, sequtils, times, math,
|
||||
terminal, osproc, random],
|
||||
system/ansi_c,
|
||||
|
||||
# Nimble packages
|
||||
stew/[objects, byteutils, endians2, io2], stew/shims/macros,
|
||||
|
@ -829,6 +830,12 @@ proc run*(node: BeaconNode) =
|
|||
notice "Shutting down after having received SIGINT"
|
||||
bnStatus = BeaconNodeStatus.Stopping
|
||||
setControlCHook(controlCHandler)
|
||||
# equivalent SIGTERM handler
|
||||
when defined(posix):
|
||||
proc SIGTERMHandler(signal: cint) {.noconv.} =
|
||||
notice "Shutting down after having received SIGTERM"
|
||||
bnStatus = BeaconNodeStatus.Stopping
|
||||
c_signal(SIGTERM, SIGTERMHandler)
|
||||
|
||||
# main event loop
|
||||
while bnStatus == BeaconNodeStatus.Running:
|
||||
|
@ -1212,6 +1219,12 @@ programMain:
|
|||
notice "Shutting down after having received SIGINT"
|
||||
quit 0
|
||||
setControlCHook(exitImmediatelyOnCtrlC)
|
||||
# equivalent SIGTERM handler
|
||||
when defined(posix):
|
||||
proc exitImmediatelyOnSIGTERM(signal: cint) {.noconv.} =
|
||||
notice "Shutting down after having received SIGTERM"
|
||||
quit 0
|
||||
c_signal(SIGTERM, exitImmediatelyOnSIGTERM)
|
||||
|
||||
if config.eth2Network.isSome:
|
||||
let metadata = getMetadataForNetwork(config.eth2Network.get)
|
||||
|
|
Loading…
Reference in New Issue