Added config reloading functionality and related subprogram

This commit is contained in:
Nocturn9x 2022-01-31 14:56:12 +01:00
parent 93b73de32a
commit 84720c1f4c
2 changed files with 21 additions and 16 deletions

View File

@ -34,7 +34,7 @@ proc mainLoop*(logger: Logger, config: NimDConfig, startServices: bool = true) =
var opType: string
try:
logger.trace("Calling initControlSocket()")
var serverSocket = initControlSocket(logger)
var serverSocket = initControlSocket(logger, config.sock)
serverSocket.listen(5)
var clientSocket = newSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
logger.switchToFile()
@ -62,7 +62,11 @@ proc mainLoop*(logger: Logger, config: NimDConfig, startServices: bool = true) =
logger.info("Received halt request")
halt(logger)
of "s":
discard # TODO
logger.info("Received service request")
# TODO: Operate on services
of "l":
logger.info("Received reload request")
mainLoop(logger, parseConfig(logger, "/etc/nimd/nimd.conf"), startServices=false)
else:
logger.warning(&"Received unknown operation type '{opType}' via control socket, ignoring it")
discard

View File

@ -25,21 +25,22 @@ proc addStuff =
## Adds stuff to test NimD. This is
## a temporary procedure
## Note: Commented because the config file now does this work!
# Adds symlinks
addSymlink(newSymlink(dest="/dev/fd", source="/proc/self/fd"))
addSymlink(newSymlink(dest="/dev/fd/0", source="/proc/self/fd/0"))
addSymlink(newSymlink(dest="/dev/fd/1", source="/proc/self/fd/1"))
addSymlink(newSymlink(dest="/dev/fd/2", source="/proc/self/fd/2"))
addSymlink(newSymlink(dest="/dev/std/in", source="/proc/self/fd/0"))
addSymlink(newSymlink(dest="/dev/std/out", source="/proc/self/fd/1"))
addSymlink(newSymlink(dest="/dev/std/err", source="/proc/self/fd/2"))
# Tests here. Check logging output (debug) to see if
# they work as intended
addSymlink(newSymlink(dest="/dev/std/err", source="/")) # Should say link already exists and points to /proc/self/fd/2
addSymlink(newSymlink(dest="/dev/std/in", source="/does/not/exist")) # Should say destination does not exist
addSymlink(newSymlink(dest="/dev/std/in", source="/proc/self/fd/0")) # Should say link already exists
addDirectory(newDirectory("test", 764)) # Should create a directory
addDirectory(newDirectory("/dev/disk", 123)) # Should say directory already exists
# addSymlink(newSymlink(dest="/dev/fd", source="/proc/self/fd"))
# addSymlink(newSymlink(dest="/dev/fd/0", source="/proc/self/fd/0"))
# addSymlink(newSymlink(dest="/dev/fd/1", source="/proc/self/fd/1"))
# addSymlink(newSymlink(dest="/dev/fd/2", source="/proc/self/fd/2"))
# addSymlink(newSymlink(dest="/dev/std/in", source="/proc/self/fd/0"))
# addSymlink(newSymlink(dest="/dev/std/out", source="/proc/self/fd/1"))
# addSymlink(newSymlink(dest="/dev/std/err", source="/proc/self/fd/2"))
# # Tests here. Check logging output (debug) to see if
# # they work as intended
# addSymlink(newSymlink(dest="/dev/std/err", source="/")) # Should say link already exists and points to /proc/self/fd/2
# addSymlink(newSymlink(dest="/dev/std/in", source="/does/not/exist")) # Should say destination does not exist
# addSymlink(newSymlink(dest="/dev/std/in", source="/proc/self/fd/0")) # Should say link already exists
# addDirectory(newDirectory("test", 764)) # Should create a directory
# addDirectory(newDirectory("/dev/disk", 123)) # Should say directory already exists
# Adds test services
var echoer = newService(name="echoer", description="prints owo", exec="/bin/echo owoooooooooo",