supervisor环境变量
2019-08-08 本文已影响0人
蕴重Liu
- 场景:supervisor启动flask失败,手动python启动成功,报错信息是缺少ModuleNotFoundError
- 配置文件:
[program:aib-humanpose]
environment=PYTHONPATH=/root/anaconda3/lib/python3.6/site-packages
command=/root/anaconda3/bin/python gateway_b_human_pose.py
directory=/ChainDevOps/lyq/AiVideoServiceEngine/src ; directory to cwd to before exec (def no cwd)
stopsignal=INT ; signal used to kill process (default TERM)
stdout_logfile=/data/log/supervisor/aib-humanpose.out.log ; stderr log path, NONE for none; default AUTO
stdout_logfile_maxbytes=4GB ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=10 ; # of stdout logfile backups (default 10)
stdout_events_enabled=true ; emit events on stdout writes (default false)
stderr_logfile=/data/log/supervisor/aib-humanpose.err.log ; stderr log path, NONE for none; default AUTO
stderr_logfile_maxbytes=1GB ; max # logfile bytes b4 rotation (default 50MB)
stderr_logfile_backups=10 ; # of stderr logfile backups (default 10)
stderr_events_enabled=true ; emit events on stderr writes (default false)
startsecs=20
-
startsecs启动时间
曾经试过tomcat的启动时间过短,内存不够,于是增加启动时间试试
结果:不是这个 -
environment环境
supervisor运行python的环境和sh的不一样
验证1-py文件,脚本中执行
import sys
print(sys.path)
验证2-supervisor配置文件
[program:test_python3]
command=/usr/local/bin/python3 /home/hunter/test.py
user=hunter
environment=AIRFLOW_HOME="/home/hunter/airflow"
- 解决问题
python通过PYTHONPATH环境变量初始化sys.path,因此需要在编写supervisor配置文件时将指定PYTHONPATH,在PYTHONPATH中添加/home/sctele/.local/lib/python3.6/site-packages便可以在sys.path中添加需要的路径。
environment=PYTHONPATH=/root/anaconda3/lib/python3.6/site-packages
对于用户python路径(pip install XXX --user安装的位置)(~/.local),也可以通过指定HOME来让python找到模块所在的路径:
environment=HOME=/home/hunter