该程序在由 cron
启动时工作。或从外壳。但是当由 upstart
开始时,它似乎无限循环。
他们使用的脚本和文件位于 /home/user/
目录,并归 user
所有, 并且都有 777
权限。
Upstart .conf 文件:
start on runlevel [2345]
stop on runlevel [!2345]
kill signal SIGHUP
# reload signal SIGHUP
respawn
exec python /home/user/Documents/init.py -b 600
最佳答案
upstart
默认以root身份执行命令。但是可以指定用户:https://askubuntu.com/questions/87671/how-do-i-start-jobs-as-a-non-privileged-user-in-upstart .
但是脚本是用 user
编写的。特定变量和对特定目录的依赖关系。
init.py 有这一行:
self.d_root = os.path.join(os.path.expanduser('~'),'Documents','records')
我把它改成了这个,它起作用了:
self.d_root = os.path.dirname(os.path.realpath(__file__))
但我认为正确的解决方法是将此行添加到
.conf
文件:setuid username
关于python - Upstart 启动 python 脚本,但行为异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30860091/