start-stop-daemon and python

走远了吗. 提交于 2019-12-04 02:14:28

I tried your script and command line, and it is working on my machine. Are you sure your script is located at /home/loop.py?

Also, don't expect to see those prints, because you are specifying the -b (background) option, so the process is being detached from your terminal. Try running it without the -b for testing purposes and then you can redirect the standard output to a logfile with the -stdout option:

sudo /sbin/start-stop-daemon --start --pidfile /home/loop.pid \ 
--user www-data --group www-data -b --make-pidfile --chuid www-data \
--exec /usr/bin/python /home/loop.py --verbose -stdout /var/log/loop.log

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"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!