Many programs allow to be run either in daemon mode (which is usually the default), or explicitly run it in foreground with a flag such as -f
.
Now when configuring upstart to run programs like this, I can either do
exec foo -f # run in foreground
or
expect fork
exec foo # automatically runs as a daemon
Is there a reason to choose one over the other? It feels that it's just easier to run everything in foreground and let upstart handle the processes, but is there a downside to that?
I strongly prefer to run things in the foreground; it avoids any complications that may arise from the daemonisation process (such as upstart losing track of the long-running daemon process). The only exception to this is a small minority of daemonising programs which have the unpleasant habit of interpreting "please run in the foreground" as "please run in some sort of poorly-performing debug mode", and do something silly like run only one thread, or don't spawn child workers, or some such.