Ubuntu下apt装的superviosr突然失效。由于安装的是老版本的supervisor,重启supervisor自身服务的时候告诉我python找不到supervisor.supervisord的库。
大概长这样1
2
3
4Starting supervisord: Traceback (most recent call last):
File "/usr/bin/supervisord", line 2, in <module>
from supervisor.supervisord import main
ImportError: No module named supervisor.supervisord
在早期supervisor使用python2.*开发的,只使用python2的环境,由于我装的比较早。所以讲python3作为默认环境的时候就不能启动原来的项目
我们先卸载原来的supervisor
Uninstall supervisor
To remove just supervisor package itself from Ubuntu 16.04 (Xenial Xerus) execute on terminal:1
sudo apt-get remove supervisor
Uninstall supervisor and it’s dependent packages
To remove the supervisor package and any other dependant package which are no longer needed from Ubuntu Xenial.1
sudo apt-get autoremove supervisor
Purging supervisor
If you also want to delete configuration and/or data files of supervisor from Ubuntu Xenial then this will work:1
sudo apt-get purge supervisor
To delete configuration and/or data files of supervisor and it’s dependencies from Ubuntu Xenial then execute:1
sudo apt-get autoremove --purge supervisor
More information about apt-get remove
Advanced Package Tool, or APT, is a free software user interface that works with core libraries to handle the installation and removal of software on Debian, Ubuntu and other Linux distributions. APT simplifies the process of managing software on Unix-like computer systems by automating the retrieval, configuration and installation of software packages, either from precompiled files or by compiling source code.
apt-get is the command-line tool for handling packages, and may be considered the user’s “back-end” to other tools using the APT library.
apt-get remove is identical to install except that packages are removed instead of installed. Note that removing a package leaves its configuration files on the system. If a plus sign is appended to the package name (with no intervening space), the identified package will be installed instead of removed.
上面介绍了几种卸载的方法。
安装supervisor
然后查阅资料显示supervisor也支持python3的版本。使用pip下载一个最新版本的。
在官网中介绍了如是使用pip下载并运行supervisor,http://supervisord.org/installing.html1
pip install supervisor
创建配置文件
Creating a Configuration File
Once the Supervisor installation has completed, run echo_supervisord_conf. This will print a “sample” Supervisor configuration file to your terminal’s stdout.
Once you see the file echoed to your terminal, reinvoke the command as echo_supervisord_conf > /etc/supervisord.conf
. This won’t work if you do not have root access.
If you don’t have root access, or you’d rather not put the supervisord.conf file in /etc/supervisord.conf
, you can place it in the current directory (echo_supervisord_conf > supervisord.conf
) and start supervisord with the -c flag in order to specify the configuration file location.
For example, supervisord -c supervisord.conf
. Using the -c flag
actually is redundant in this case, because supervisord searches the current directory for a supervisord.conf before it searches any other locations for the file, but it will work. See Running Supervisor for more information about the -c flag.
我默认放到的路径在/etc/supervisor
于原来保持一致。
配置supervisor
wechat.conf1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31[program:wechat_doonsec_test]
directory=/home/all/WechatTogether
command=python app.py
autostart=false
autorestart=false
startretries=10
redirect_stderr=true
stderr_logfile=/etc/supervisor/logs/wechat_err.log
stdout_logfile=/etc/supervisor/logs/wechat.log
[program:wechat_doonsec_bak]
directory=/home/all/WechatTogether
command=gunicorn -b 127.0.0.1:7010 -w 1 --threads 20 -k gevent app:app
autostart=true
autorestart=true
startretries=10
redirect_stderr=true
stderr_logfile=/etc/supervisor/logs/wechat_err.log
stdout_logfile=/etc/supervisor/logs/wechat.log
[program:wechat_doonsec]
directory=/home/all/WechatTogether
command=gunicorn -b 127.0.0.1:7001 -w 1 --threads 20 -k gevent app:app
autostart=true
autorestart=true
startretries=10
redirect_stderr=true
stderr_logfile=/etc/supervisor/logs/wechat_err.log
stdout_logfile=/etc/supervisor/logs/wechat.log
开启网页版服务的端口
supervisord.conf1
找到端口部分开启
运行supervisor
1 | supervisord -c /etc/supervisor/supervisord.conf |
查看任务的方式
命令行版本
1 | supervisorctl status |
启动任务、暂停任务等
1 | reread ;重新加载配置文件 |
常用命令
1 | sudo service supervisor stop 停止supervisor服务 |
网页版本
输入ip+开启的端口+账密。就能看到所有的任务,傻瓜式操作。
开机启动
a.在指定目录下创建文件supervisord.service1
vim /usr/lib/systemd/system/supervisord.service
b.输入以下内容:1
2
3
4
5
6
7
8
9
10
11
12
13
14[Unit]
Description=Supervisor daemon
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
保存并退出
执行以下命令:1
systemctl enable supervisord
提示:1
Created symlink from /etc/systemd/system/multi-user.target.wants/supervisord.service to /usr/lib/systemd/system/supervisord.service.
验证是否为开机启动:1
systemctl is-enabled supervisord
提示:1
enabled
表示设置成功!
至此,创建supervisor守护进程完毕。
附件
配置说明
1 | ;*为必须填写项 |