2022-01-10 15:32:56 +00:00
|
|
|
## Nim-Dagger
|
|
|
|
## Copyright (c) 2021 Status Research & Development GmbH
|
|
|
|
## Licensed under either of
|
|
|
|
## * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
|
|
|
## * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
|
|
|
## at your option.
|
|
|
|
## This file may not be copied, modified, or distributed except according to
|
|
|
|
## those terms.
|
|
|
|
|
|
|
|
import pkg/chronicles
|
|
|
|
import pkg/chronos
|
|
|
|
import pkg/confutils
|
|
|
|
import pkg/libp2p
|
|
|
|
|
|
|
|
import ./dagger/conf
|
|
|
|
import ./dagger/dagger
|
|
|
|
|
|
|
|
export dagger, conf, libp2p, chronos, chronicles
|
|
|
|
|
|
|
|
when isMainModule:
|
|
|
|
import std/os
|
|
|
|
|
|
|
|
import pkg/confutils/defs
|
|
|
|
|
|
|
|
import ./dagger/utils/fileutils
|
|
|
|
|
|
|
|
when defined(posix):
|
|
|
|
import system/ansi_c
|
|
|
|
|
2022-04-12 13:21:07 +00:00
|
|
|
let config = DaggerConf.load()
|
|
|
|
config.setupLogging()
|
2022-01-10 15:32:56 +00:00
|
|
|
|
|
|
|
case config.cmd:
|
|
|
|
of StartUpCommand.noCommand:
|
|
|
|
|
|
|
|
if not(checkAndCreateDataDir((config.dataDir).string)):
|
|
|
|
# We are unable to access/create data folder or data folder's
|
|
|
|
# permissions are insecure.
|
|
|
|
quit QuitFailure
|
|
|
|
|
|
|
|
trace "Data dir initialized", dir = config.dataDir
|
|
|
|
|
|
|
|
if not(checkAndCreateDataDir((config.dataDir / "repo").string)):
|
|
|
|
# We are unable to access/create data folder or data folder's
|
|
|
|
# permissions are insecure.
|
|
|
|
quit QuitFailure
|
|
|
|
|
|
|
|
trace "Repo dir initialized", dir = config.dataDir / "repo"
|
|
|
|
|
|
|
|
let server = DaggerServer.new(config)
|
|
|
|
|
|
|
|
## Ctrl+C handling
|
|
|
|
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 # shouldn't happen
|
|
|
|
notice "Shutting down after having received SIGINT"
|
2022-04-06 00:34:29 +00:00
|
|
|
waitFor server.stop()
|
2022-01-10 15:32:56 +00:00
|
|
|
|
|
|
|
try:
|
|
|
|
setControlCHook(controlCHandler)
|
|
|
|
except Exception as exc: # TODO Exception
|
|
|
|
warn "Cannot set ctrl-c handler", msg = exc.msg
|
|
|
|
|
|
|
|
# equivalent SIGTERM handler
|
|
|
|
when defined(posix):
|
|
|
|
proc SIGTERMHandler(signal: cint) {.noconv.} =
|
|
|
|
notice "Shutting down after having received SIGTERM"
|
2022-04-06 00:34:29 +00:00
|
|
|
waitFor server.stop()
|
2022-01-10 15:32:56 +00:00
|
|
|
|
|
|
|
c_signal(SIGTERM, SIGTERMHandler)
|
|
|
|
|
2022-04-06 00:34:29 +00:00
|
|
|
waitFor server.start()
|
2022-01-10 15:32:56 +00:00
|
|
|
of StartUpCommand.initNode:
|
|
|
|
discard
|