(SOLUTION NOTE: The problem is that the service, written in python, buffers it's stdout/stderr. Unbuffered output can be designated by adding -u
to the command, or by setting the env var PYTHONBUFFERED=0
.
For serious logging it is better to send directly to /dev/log
, e.g. use the Python module logging.handlers.SysLogHandler
and avoid the extra layer of going through procd
indirection. For example it was found that procd
did not report a Connection Failed 111
error for /dev/log
when it was in an error state.
Thanks to @yousong@ for their great help and "no buffering" solution to this problem.)
I have written a service file with procd
commands.
The service runs and functions correctly but the log output is not output the buffer shown by logread
.
The start_service()
function is as follows:
DGH_CMD="/usr/bin/python3 /work/dgh/dns-mitm.py"
DGH_PARAM=" -b 192.168.11.24 -v 2"
...
start_service() {
procd_open_instance dgh
procd_set_param command $DGH_CMD
procd_append_param command $DGH_PARAM
# respawn automatically if something died,
# be careful if you have an alternative process supervisor
# if process dies sooner than respawn_threshold,
# it is considered crashed and after 5 retries the service is stopped
procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
procd_set_param user root # run service as user nobody
procd_set_param limits core="unlimited" # If you need to set ulimit for your process
# forward stdout and stderr of the command to logd
procd_set_param stdout 1
procd_set_param stderr 1
procd_set_param pidfile /var/run/dgh.service.pid # write a pid file on instance start and remote it on stop
procd_close_instance
echo "dgh: start_service() invoking $DGH_CMD RESULT=$?"
}
I also tested with procd_close_instance
removed - no difference and it still ran.
# procd_close_instance
I noticed that the only other service files files in my setup (which amd64 18.06.2 release) which contain procd_set_param stdout 1
or procd_set_param stderr 1
are
- uhttpd
- urandom_seed
For a test I restarted these services to see if anything would show up with logread
, but nothing did. Of course that is proof of nothing, except that I couldn't eliminate that possibility that procd_set_param stdout/stderr 1
isn't functioning. Other logging such as from dropbear
and nftables
are working correctly, but dropbear is not using the procd_set_param stdout/stderr 1
in its service file.
Is there another way to set logging?