Add graceful shutdown handler for SIGINT and SIGTERM.
This commit is contained in:
+6
-1
@@ -1,4 +1,4 @@
|
|||||||
import std/[json, nre, sequtils, strutils]
|
import std/[json, nre, posix, sequtils, strutils]
|
||||||
import cliutils, docopt, mummy, namespaced_logging
|
import cliutils, docopt, mummy, namespaced_logging
|
||||||
import webby/httpheaders
|
import webby/httpheaders
|
||||||
|
|
||||||
@@ -91,6 +91,11 @@ when isMainModule:
|
|||||||
elif args["--debug"]: logSvc.setRootThreshold(lvlDebug)
|
elif args["--debug"]: logSvc.setRootThreshold(lvlDebug)
|
||||||
|
|
||||||
let server = newServer(makeHandler(cfg.mappings, logSvc))
|
let server = newServer(makeHandler(cfg.mappings, logSvc))
|
||||||
|
|
||||||
|
onSignal(SIGINT, SIGTERM):
|
||||||
|
logger.info("short_url shutting down")
|
||||||
|
server.close()
|
||||||
|
|
||||||
logger.info("short_url v$# listening for requests on $#" %
|
logger.info("short_url v$# listening for requests on $#" %
|
||||||
[ VERSION, $cfg.port ])
|
[ VERSION, $cfg.port ])
|
||||||
server.serve(Port(cfg.port), address = "0.0.0.0")
|
server.serve(Port(cfg.port), address = "0.0.0.0")
|
||||||
|
|||||||
Reference in New Issue
Block a user