I have an init.d
script that runs a binary as a daemon. The binary regularly writes status lines to stdout. I would like to log those lines into /var/log/my-daemon
.
When the start code is like this:
start-stop-daemon -S -x $DAEMON -- $ARGS
And I run service my-daemon restart
, then I get the log output on... stdout. But obviously, I want to run it in background, and save the logs to a file.
I want something like this (inspired by this):
start-stop-daemon -S --background -x $DAEMON -- $ARGS >> /var/log/my-daemon 2>&1
But this does not log anything to the log file. From the man page of start-stop-daemon
, it sounds like --no-close
would be the right thing to use here. But my system uses start-stop-daemon
from Busybox:
BusyBox v1.32.0 () multi-call binary.
Usage: start-stop-daemon [OPTIONS] [-S|-K] ... [-- ARGS...]
Which does not seem to support -C
or --no-close
.
Is there a solution to that, or do I need to change my init system because I won't be able to achieve what I want with Busybox?
Note: the following seems to work (at least sometimes), but feels wrong (otherwise there would be no need for --background
, right?):
start-stop-daemon -S -x $DAEMON -- $ARGS >> /var/log/my-daemon 2>&1 &