前言
supervisor 是一个非常方便的进程管理器,具体怎么方便百度上有很多,这里只是介绍一下在 ubuntu 系统下的 python3 安装和使用。
安装
- 安装命令
pip install supervisor
这里我的pip已经默认指向 python3 的 pip 了,因为 supervisor 已经支持 python3 了 - 然后执行 supervisord 命令来测试一下,不出意外,报错了!!!
pkg_resources.DistributionNotFound: The 'supervisor==3.3.1' distribution was not found and is required by the application
原因是系统还是装了一个 python2 的 supervisor 虽然 python3 也装上了,但是默认会使用 python2 的命令,我们需要彻底删除干净 - 先使用
pip uninstall supervisor
删除一下 python3的以防出现其他问题,然后执行apt-get --purge remove supervisor
,来删除python2的supervisor ,这时候再执行pip install supervisor
就可以装上了, 请注意,我系统默认的pip已经指向了python3的pip,本次错误最主要的任务是要删除python2的supervisor - 执行 pip 命令以后会有如下界面:
WARNING: The scripts echo_supervisord_conf, pidproxy, supervisorctl and supervisord are installed in ‘/usr/local/python3/bin’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed supervisor-4.1.0
意思是安装成功了, echo_supervisord_conf, pidproxy, supervisorctl 和 supervisord 已经安装到 python3 了,但是 python3 没有放到环境变量中
- 这时候我们要把 python3 加入环境变量中,上面已经提示了 python3 的路径是 /usr/local/python3/bin
vim ~/.profile
export PATH=$PATH:/usr/local/python3/bin
source ~/.profile
然后执行
supervisord
/usr/local/python3/lib/python3.7/site-packages/supervisor/options.py:471: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a “-c” argument specifying an absolute path to a configuration file for improved security.
意思是 supervisord 什么的已经安装成功了!!只是 supervisord 命令需要指定一些参数,不过结果是确实配置成功了!!
结尾
supervisor 的其他命令网上都可以很方便的找到,然后怎么配置,如何部署应用也都有教程,这里我强烈推荐 Nginx+Gunicorn+Supervisor 部署 Django 博客应用
里面有讲到很多 supervisor 的部署方面的细节。