start-stop-daemon and python

前端 未结 2 2247
再見小時候
再見小時候 2021-02-20 13:12

I\'m trying to start python script with start-stop-daemon:

sudo /sbin/start-stop-daemon --start --pidfile /home/loop.pid \\ 
--user www-data --group www-data -b          


        
2条回答
  •  星月不相逢
    2021-02-20 13:44

    Rather than exec python directly, if you --exec (or --startas) a nested shell, then you can do the redirection in there (as per this answer):

    start-stop-daemon --start --quiet --chuid $DAEMONUSER    \
     --make-pidfile --pidfile $PIDFILE --background       \
     --startas /bin/bash -- -c "exec $DAEMON $DAEMON_ARGS > /var/log/some.log 2>&1"
    

    This works for me and logs my Python stdout quite happily once I realized the output was buffered (my script wasn't writing very much)! I then found this article which uses 'stdbuf' to flush to the output more eagerly than the default (and also explains it quite well):

    start-stop-daemon --start --background \
                --pidfile $PIDFILE --make-pidfile --startas /bin/bash \
                -- -c "exec stdbuf -oL -eL $DAEMON $DAEMONARGS > $LOGFILE 2>&1"
    

提交回复
热议问题