Wholeheartedly recommend not reinventing the daemon wheel - self-daemonizing
programs and self log-rotating problems never do things quite the way one needs.
use systemd, if that's what on your system, or (I recommend) a djb-inspired
system: daemontools, s6, nosh , etc - they are ultra simple an
I wrote this nim program to elevate other programs to daemon status (and
restart them if they crash):
[https://github.com/treeform/guardmons/blob/master/daemon.nim](https://github.com/treeform/guardmons/blob/master/daemon.nim)
handle with
[setControlCHook](https://nim-lang.org/docs/system.html#setControlCHook%2Cproc%29)
proc
Thank you all for the suggestions. Just one more question: How do I catch a
"KILL" or "HUP" or user abort signal (CTRL-C)?
There are different init system and tools to run an application as a daemon
without having to increase your application's complexity. Currently a lot of
distributions ship systemd by default as it provides features like automated
health check and restart and security sandboxing.
I wrote a littl
I usually make the executable as service using [this
reference](https://gist.github.com/bcap/5397674)
For userland it may be good enough (altough you may want to control the log and
pid file from within your Nim application). Some OS distributions may even
provide a "deamon" command / tool that run your application in that mode (kind
of
[http://libslack.org/daemon/manpages/daemon.1.html](http:/
This work:
$ ./server -p 8080 &> ./logs/server.log & echo $! > ./server.pid;
But is this the correct approach?