mirror of https://github.com/nocturn9x/nimd.git
Compare commits
3 Commits
93b73de32a
...
a0a49874bb
Author | SHA1 | Date |
---|---|---|
Nocturn9x | a0a49874bb | |
Nocturn9x | 5e4aed7e0f | |
Nocturn9x | 84720c1f4c |
|
@ -155,7 +155,7 @@ proc removeDirectory*(directory: Directory) =
|
|||
|
||||
|
||||
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
|
||||
## 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
|
||||
|
|
|
@ -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()
|
||||
|
@ -51,6 +51,7 @@ proc mainLoop*(logger: Logger, config: NimDConfig, startServices: bool = true) =
|
|||
# - 'r' -> reboot
|
||||
# - 'h' -> halt
|
||||
# - 's' -> Services-related operations (start, stop, get status, etc.)
|
||||
# - 'l' -> Reload in-memory configuration
|
||||
case opType:
|
||||
of "p":
|
||||
logger.info("Received shutdown request")
|
||||
|
@ -62,7 +63,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
|
||||
|
|
|
@ -108,11 +108,10 @@ proc resolve(logger: Logger, node: Service): seq[Service] =
|
|||
## sorted list such that a service appears in it only
|
||||
## after all of its dependencies and only
|
||||
## before all of its dependents.
|
||||
## This function also automatically handles
|
||||
## detached subgraphs, which can occurr if
|
||||
## one or more dependencies have common
|
||||
## dependencies/dependents between each other,
|
||||
## but not with the rest of the graph. Nodes
|
||||
## This function is called iteratively by resolveDependencies
|
||||
## to handle detached subgraphs, which can occurr if one or
|
||||
## more dependencies have common dependencies/dependents between
|
||||
## each other, but not with the rest of the graph. Nodes
|
||||
## that have no dependencies nor provide any
|
||||
## service may be located anywhere in the list,
|
||||
## as that does not invalidate the invariants
|
||||
|
|
29
src/main.nim
29
src/main.nim
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue