mac配置supervisor

mac2022-06-30  30

mac配置supervisor

安装

brew install supervisor

启动

一种是手动

supervisord -c /usr/local/etc/supervisord.ini

让supervisor随系统自启动

brew services start supervisor

查看配置文件

使用

echo_supervisord_conf

经常启动或者停止

supervisor> reload Really restart the remote supervisord process y/N? y Restarted supervisord supervisor> start spider logstash: started supervisor> stop spider

spider是我后面用到spider.ini

supervisord.ini配置文件修改

cd /usr/local/etc vim supervisord.ini

启动网页版

[inet_http_server] ; inet (TCP) server disabled by default port=127.0.0.1:9001 ; ip_address:port specifier, *:port for all iface username=cxa ; default is no username (open server) password=123 ; default is no password (open server)

输入127.0.0.1:9001可以打开网页

用户名cxa 密码123

[include] files = /usr/local/etc/supervisor.d/*.ini

上面两行是该配置文件的最后不用修改,这里说下意思,表示的是/usr/local/etc/supervisor.d这个文件下.ini文件就是要启动的文件。 如果supervisor.d没有就创建一个,反正我是自己创建的。

创建程序配置文件

下面就是需要运行的文件的配置,这个文件的位置是 /usr/local/etc/supervisor.d/spider.ini

[program:spider] #指定当前的文件名 directory = /Users/chennan/Desktop/2019/spiderdemo/ #运行程序的当前目录 command = python3 spider.py #运行命令 autostart = false startsecs = 5 autorestart = true startretries = 3 user = chennan #电脑用户名 redirect_stderr = true stdout_logfile_backups = 20 stdout_logfile=/Users/chennan/Desktop/2019/spiderdemo/logs/spider.log #log文件目录 stdout_logfile_maxbytes=1024MB #单个文件容量1g应该够用,不够加大。 stderr_logfile=/Users/chennan/Desktop/2019/spiderdemo/logs/spider_err.log #出错的log文件目录 stderr_logfile_maxbytes=1024MB environment=PYTHONPATH=$PYTHONPATH:/usr/local/bin/python3

运行

可以通过127.0.0.1:9001 打开页面运行,然后点击程序名可以查看程序的输出内容. 或者依次运行下面命令

supervisorctl -c /usr/local/etc/supervisord.ini supervisor> supervisor> reload Really restart the remote supervisord process y/N? y Restarted supervisord supervisor> start logstash spider: started supervisor> status #可以查看运行状态

错误处理

如果出现下面错误

unix:///usr/local/var/run/supervisor.sock no such file

查看进程

ps -ef |grep supervisor

杀死进程

pkill -f supervisord

然后再来一次

supervisorctl -c /usr/local/etc/supervisord.ini supervisor> supervisor> reload Really restart the remote supervisord process y/N? y Restarted supervisord supervisor> start spider spider: started supervisor> status #可以查看运行状态

注意程序不会停止会一直运行,即使出错也会重新运行。太深了我没研究,做记录用的。

转载于:https://www.cnblogs.com/c-x-a/p/10231065.html

最新回复(0)