mirror of https://github.com/nocturn9x/nimd.git
Minor changes to error handling in main loop + changes to boot script and config
This commit is contained in:
parent
5f965826ea
commit
38698ec72a
|
@ -7,7 +7,7 @@ restartDelay = 10
|
|||
sigtermDelay = 90
|
||||
|
||||
[Logging]
|
||||
level = info
|
||||
level = debug
|
||||
logFile = /var/log/nimd
|
||||
|
||||
[Filesystem]
|
||||
|
|
|
@ -112,4 +112,4 @@ if ! [[ $memory -eq "" ]]
|
|||
qemumem="-m ${memory}"
|
||||
fi
|
||||
|
||||
qemu-system-x86_64 -net nic,model=virtio,netdev=user.0 -netdev user,id=user.0 -drive file=vm.qcow2,if=virtio -enable-kvm -kernel ${kernel} -initrd ${initrd} ${qemumem} -append 'root=/dev/vda1 rw quiet modules=ext4 console=ttyS0,9600 console=ttyS0 init=/bin/nimd'
|
||||
qemu-system-x86_64 -net nic,model=virtio,netdev=user.0 -netdev user,id=user.0 -drive file=vm.qcow2,if=virtio -enable-kvm -kernel ${kernel} -initrd ${initrd} ${qemumem} -append 'root=/dev/vda1 rw quiet modules=ext4 console=ttyS0 init=/bin/nimd'
|
||||
|
|
|
@ -40,6 +40,7 @@ proc mainLoop*(logger: Logger, config: NimDConfig, startServices: bool = true) =
|
|||
logger.switchToFile()
|
||||
logger.debug("Entering accept() loop")
|
||||
while true:
|
||||
try:
|
||||
serverSocket.accept(clientSocket)
|
||||
logger.debug(&"Received connection on control socket")
|
||||
if clientSocket.recv(opType, size=1) == 0:
|
||||
|
@ -75,7 +76,11 @@ proc mainLoop*(logger: Logger, config: NimDConfig, startServices: bool = true) =
|
|||
else:
|
||||
logger.warning(&"Received unknown operation type '{opType}' via control socket, ignoring it")
|
||||
discard
|
||||
except:
|
||||
logger.error(&"An error occurred while idling on control socket: {getCurrentExceptionMsg()}")
|
||||
finally:
|
||||
clientSocket.close()
|
||||
clientSocket = newSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
|
||||
except:
|
||||
logger.critical(&"A critical error has occurred while running, restarting the main loop in {config.restartDelay} seconds! Error -> {getCurrentExceptionMsg()}")
|
||||
sleepSeconds(config.restartDelay)
|
||||
|
|
|
@ -59,7 +59,7 @@ proc addStuff =
|
|||
depends=(@[newDependency(Other, errorer)]), provides=(@[]),
|
||||
stdin="/dev/null", stderr="", stdout="")
|
||||
var shell = newService(name="login", description="A simple login shell", kind=Simple,
|
||||
workDir=getCurrentDir(), runlevel=Boot, exec="/bin/login -f root",
|
||||
workDir=getCurrentDir(), runlevel=Default, exec="/bin/login -f root",
|
||||
supervised=true, restart=Always, restartDelay=0, depends=(@[]), provides=(@[]),
|
||||
useParentStreams=true, stdin="/dev/null", stderr="/proc/self/fd/2", stdout="/proc/self/fd/1"
|
||||
)
|
||||
|
@ -74,8 +74,12 @@ proc checkControlSocket(logger: Logger, config: NimDConfig): bool =
|
|||
## socket
|
||||
result = true
|
||||
var stat_result: Stat
|
||||
if posix.stat(cstring(config.sock), stat_result) == -1:
|
||||
if posix.stat(cstring(config.sock), stat_result) == -1 and posix.errno != 2:
|
||||
logger.warning(&"Could not stat() {config.sock}, assuming NimD instance isn't running")
|
||||
elif posix.errno == 2:
|
||||
logger.debug(&"Control socket path is clear, starting up")
|
||||
posix.errno = 0
|
||||
# 2 is ENOENT, which means the file does not exist
|
||||
# I stole this from /usr/lib/python3.10/stat.py
|
||||
elif (int(stat_result.st_mode) and 0o170000) != 0o140000:
|
||||
logger.fatal(&"{config.sock} exists and is not a socket")
|
||||
|
|
Loading…
Reference in New Issue