mirror of
https://github.com/logos-storage/logos-storage-network-crawler.git
synced 2026-01-02 13:33:08 +00:00
44 lines
1.1 KiB
Nim
44 lines
1.1 KiB
Nim
import std/os
|
|
import pkg/chronicles
|
|
import pkg/chronos
|
|
import pkg/questionable
|
|
import pkg/questionable/results
|
|
|
|
import ./codexcrawler/application
|
|
|
|
when defined(posix):
|
|
import system/ansi_c
|
|
|
|
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() =
|
|
app.stop()
|
|
notice "Stopping Crawler..."
|
|
|
|
proc controlCHandler() {.noconv.} =
|
|
when defined(windows):
|
|
# workaround for https://github.com/nim-lang/Nim/issues/4057
|
|
try:
|
|
setupForeignThreadGc()
|
|
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()
|