supervisor是一个用于监控和自动重启的管理进程的工具,可以用在自动运维 auto healing 中
https://www.youtube.com/watch?v=eX7D40y9qv8
按照这个例子做了一下测试,启动后即使杀掉进程,supervisor仍然可以自动启动进程。
可以用supervisor 管理apache,postgresql, 等进程
也可以和containerd 结合管理container 的停止、重启、监听等。
supervisord vs. supervisorctl
supervisorctl could be considered as the delegation of supervisord,
Here are the explanation in supervisor doc:
If supervisord is started as root, it is possible to allow “normal” users to control such processes without needing to explain the intricacies of the problem to them. Supervisorctl allows a very limited form of access to the machine, essentially allowing users to see process status and control supervisord-controlled subprocesses by emitting “stop”, “start”, and “restart” commands from a simple shell or web UI.
reread, reload,restart,update 区别
restart:重启进程,并不会重新读取配置文件,所以服务实际未使用新配置
reread:只会更新配置文件,不会重启进程,所以服务实际未使用新配置
update:更新配置文件,并重启配置文件有更新的进程,相当于 reread + restart,所以服务会使用新配置
reload:重启supervisord,相当于更新所有服务的配置文件,并重启所有服务(谨慎使用)
常见的supervisor 错误
用 ps -ef | grep supervisord 查看一下进程是否正常启动,需要的话杀掉现在的进程
- "class 'FileNotFoundError' , [Errno 2] No such file or directory:....xmlrpc.py"
这个错误原因很多,一般是重新reload supervisorctl
我查到最后发现是因为mac 中自带的httpd的启动占用了80端口
用 lsof -nP -i TCP:80 | grep LISTEN 查看是哪个进程占用了80端口
然后把apachectl 停止后这个问题解决了。
- "http://127.0.0.1:9001 refused connection"
查看supervisor.conf 设置,inet_http_server 和 supervisorctl 的配置都要设好,参看:https://www.cnblogs.com/ryanlamp/p/7279369.html
还有一个问题没有解决,就是9001虽然解决,但在container中启动后,想要从browser上查看supervisor 的管理页面仍然没有看到,暂时搁置一下,等待后续研究
其他supervisor还有一个event 监听功能可以做更加细致的管理
目前主要用在进程的重启、停止等方面。
网友评论