Compare commits

...

3 Commits

Author SHA1 Message Date
Nocturn9x a0a49874bb Minor changes to docstrings 2022-01-31 15:06:43 +01:00
Nocturn9x 5e4aed7e0f Added comment about new reload operation in mainloop 2022-01-31 14:58:29 +01:00
Nocturn9x 84720c1f4c Added config reloading functionality and related subprogram 2022-01-31 14:56:12 +01:00
4 changed files with 27 additions and 22 deletions

View File

@ -155,7 +155,7 @@ proc removeDirectory*(directory: Directory) =
proc parseFileSystemTable*(fstab: string): seq[Filesystem] = proc parseFileSystemTable*(fstab: string): seq[Filesystem] =
## Parses the contents of the given filesystem table and returns a Filesystem object. ## Parses the contents of the given filesystem table and returns a list of Filesystem objects.
## An improperly formatted or semantically invalid fstab will cause this function to ## An improperly formatted or semantically invalid fstab will cause this function to
## error out with a ValueError exception that should be caught by the caller. ## error out with a ValueError exception that should be caught by the caller.
## No other checks other than very basic syntax are performed, as that job ## No other checks other than very basic syntax are performed, as that job

View File

@ -34,7 +34,7 @@ proc mainLoop*(logger: Logger, config: NimDConfig, startServices: bool = true) =
var opType: string var opType: string
try: try:
logger.trace("Calling initControlSocket()") logger.trace("Calling initControlSocket()")
var serverSocket = initControlSocket(logger) var serverSocket = initControlSocket(logger, config.sock)
serverSocket.listen(5) serverSocket.listen(5)
var clientSocket = newSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP) var clientSocket = newSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
logger.switchToFile() logger.switchToFile()
@ -51,6 +51,7 @@ proc mainLoop*(logger: Logger, config: NimDConfig, startServices: bool = true) =
# - 'r' -> reboot # - 'r' -> reboot
# - 'h' -> halt # - 'h' -> halt
# - 's' -> Services-related operations (start, stop, get status, etc.) # - 's' -> Services-related operations (start, stop, get status, etc.)
# - 'l' -> Reload in-memory configuration
case opType: case opType:
of "p": of "p":
logger.info("Received shutdown request") logger.info("Received shutdown request")
@ -62,7 +63,11 @@ proc mainLoop*(logger: Logger, config: NimDConfig, startServices: bool = true) =
logger.info("Received halt request") logger.info("Received halt request")
halt(logger) halt(logger)
of "s": 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: else:
logger.warning(&"Received unknown operation type '{opType}' via control socket, ignoring it") logger.warning(&"Received unknown operation type '{opType}' via control socket, ignoring it")
discard discard

View File

@ -108,11 +108,10 @@ proc resolve(logger: Logger, node: Service): seq[Service] =
## sorted list such that a service appears in it only ## sorted list such that a service appears in it only
## after all of its dependencies and only ## after all of its dependencies and only
## before all of its dependents. ## before all of its dependents.
## This function also automatically handles ## This function is called iteratively by resolveDependencies
## detached subgraphs, which can occurr if ## to handle detached subgraphs, which can occurr if one or
## one or more dependencies have common ## more dependencies have common dependencies/dependents between
## dependencies/dependents between each other, ## each other, but not with the rest of the graph. Nodes
## but not with the rest of the graph. Nodes
## that have no dependencies nor provide any ## that have no dependencies nor provide any
## service may be located anywhere in the list, ## service may be located anywhere in the list,
## as that does not invalidate the invariants ## as that does not invalidate the invariants

View File

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