【发布时间】:2018-07-26 20:33:38
【问题描述】:
使用 ubuntu 的 16.04 crontab 和 @reboot 来运行 python3 脚本。当我看到记录的输出时,脚本在重新启动时正常运行。但是,我的脚本的 os.system 命令没有运行。如果在 crontab 之外运行,它运行良好。我的脚本都是可执行的。
crontab -l 输出:
SHELL=/bin/bash
@reboot nohup /usr/bin/python3 -u /home/path/scheduler.py >> /path/log.out &
scheduler.py 代码:
#...(check if web server is running...if not restart)
os.system('nohup /usr/bin/python3 -u /path/webserver/main.py &')
print('this function ran')
当我记录 os.system 命令的输出时,没有输出。
附带说明一下,我正在运行 python 调度命令来检查网络服务器的总体健康状况。 crontab 似乎不是正确的工具,所以我只使用 crontab 在重启时启动我的 python 调度程序。
我使用烧瓶作为网络服务器,如果我可以让它工作,我会使用 gunicorn 和 systemctrl...但它没有,所以这是我的解决方法。
【问题讨论】:
-
即使你找到了答案,这似乎也是个麻烦事。我建议您使用更标准的解决方案(supervisord 或 systemctl)解决您遇到的问题,而不是对自制解决方案进行故障排除。你遇到了什么样的问题?
-
@MrName,你可能是对的。在我回到 supervisord/systemctl 之前,这似乎是一个简单的解决方法。有了这两个和gunicorn,问题接踵而至。足以让我尝试找到一个更简单的解决方案(如 python schedule)。
-
我肯定知道,去过那里,但可能非常令人沮丧。如果您需要帮助解决这些问题,请告诉我,我会尽力而为。