The design pattern for spawning web server workers seems to be that they are started by root in an init script and then spawn a process as an unprivileged user. For example, I start a gunicorn web server daemon in an init script like this:
#!/bin/sh
$LOGFILE=/var/log/gunicorn.error.log
$PIDFILE=/var/run/gunicorn.pid
[...]
gunicorn -u nobody -b 127.0.0.1:8000 \
--error-logfile=$LOGFILE --pidfile=$PIDFILE -D
I can spawn my own scripts as an unprivileged user (see this question), but that process can no longer write log files to /var/log
.
How do I enable a worker spawned by a root
process to write log files to /var/log
and PID files to /var/run
?