python - Upstart 启动 python 脚本,但行为异常

标签 python ubuntu upstart

该程序在由 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/

相关文章:

python - 找不到有效的 Python 解释器。请在您的 LaTeXTools 设置中设置 python 设置

Python正则表达式计算数字、字母出现的次数

ubuntu - 无法连接到 Docker 守护程序。 docker 守护进程是否在此主机上运行?

ubuntu - 增加 Ubuntu/Upstart 的最大打开文件数(initctl)

bash - 无法在 UpStart 中声明数组,但可以在 bash 中声明

python - Tornadoweb webapp 无法通过 upstart 进行管理

python - 如何为 django-cities-light country 模型添加资本?

python - Python 中 "string"的逻辑值是多少?

c - fscanf 读访问段错误

wordpress 网站显示跳转到内容