Hacker News new | ask | show | jobs
by a-dub 1909 days ago
i must say though, i'm not sure how i feel about a shell script "daemon"...
2 comments

Daemon is just something running in a loop.
actually no. there are a bunch of properties to properly daemonize in unix. things like special handling for stdin/stdout/stderr, reparenting, signal handling... look it up.

classic rookie mistake to just call a program that doesn't exit a daemon...

proper daemons can stay up for years.

Infinite loop will stay up for years too.

Running "in the background", handling of stdin/out/err, logging, detaching from tty, creating a new process group/session, closing fds, and much more is handled these days mostly by systemd. No need to put all this into your program at all.

I'll give you that signal handling still needs to be done in the target process, if the defaults don't satisfy you.

But you really don't need anything special anymore to make any old script into a daemon.

so if your daemon is ever started by hand or is used on a system without systemd it won't work correctly? that doesn't sound great.
Only time I'm starting daemon by hand is to debug it. So having it stay in foreground and log to console is good in that case.
so if someone else starts it by hand it won't work correctly?

if someone else runs it on a system without systemd it won't work correctly?

Why? This is not a completely novel concept, and a daemon is not a particularly complicated thing. You can use shell scripts to easily "daemonize" small programs. It's both fun and effective to do so.