40 lines
990 B
Nim
Raw Permalink Normal View History

import pkg/chronicles
2025-02-05 16:06:04 +01:00
import ./codexcrawler/application
2025-02-05 10:52:15 +01:00
when defined(posix):
import system/ansi_c
2025-02-04 10:50:46 +01:00
when isMainModule:
let app = Application()
# Stopping code must be in scope of app declaration.
# Else capture of the instance is not allowed due to {.noconv.}.
proc onStopSignal() =
2025-02-05 16:06:04 +01:00
app.stop()
notice "Stopping Crawler..."
proc controlCHandler() {.noconv.} =
when defined(windows):
# workaround for https://github.com/nim-lang/Nim/issues/4057
try:
setupForeignThreadGc()
2025-02-05 11:06:18 +01:00
except Exception as exc:
raiseAssert exc.msg
notice "Shutting down after having received SIGINT"
onStopSignal()
try:
setControlCHook(controlCHandler)
except Exception as exc:
warn "Cannot set ctrl-c handler", msg = exc.msg
when defined(posix):
proc SIGTERMHandler(signal: cint) {.noconv.} =
notice "Shutting down after having received SIGTERM"
onStopSignal()
c_signal(ansi_c.SIGTERM, SIGTERMHandler)
app.run()