supervisor 是一个很好用的进程管理工具,我的laravel项目用到了定时功能,再此写以下supervisor的安装配置.
1 最简单的安装方法(但是我的机器yum源找不到,于是我决定使用编译方法安装)
# yum install supervisor
2 编译安装supervisor 官网 https://pypi.python.org/pypi/supervisor/
2.1 下载编译
# wget https://pypi.python.org/packages/44/80/d28047d120bfcc8158b4e41127706731ee6a3419c661e0a858fb0e7c4b2d/supervisor-3.3.0.tar.gz # tar -zxvf supervisor-3.3.0.tar.gz # python setup.py install
2.2 在安装的过程中报了如下错误 (通过 http://blog.csdn.net/newjueqi/article/details/47446965 顺利解决问题 )
# python setup.py install Traceback (most recent call last): File "setup.py", line 34, in <module> from setuptools import setup, find_packages ImportError: No module named setuptools
2.3 进入python看是否安装好
# python Python 2.7.6 (default, May 17 2016, 05:43:50) [GCC 4.4.7 20120313 (Red Hat 4.4.7-16)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import supervisor >>>
2.4 生成supervisord 配置文件 (echo_supervisord_conf 在你安装的python bin目录中)
# mkdir /etc/supervisor # echo_supervisord_conf > /etc/supervisor/supervisord.conf
3 配置使用supervisor
# vi /etc/supervisor/supervisord.conf # 最后两行去掉#号 更改为 [include] files = /etc/supervisor/conf.d/*.conf # mkdir conf.d # cd conf.d # vi test.conf [program:redshu_queue] # 此定时任务的名字 command = php /home/www/redshu/artisan queue:listen --timeout=360 # 你要定时执行的命令 更多配置 http://supervisord.org/configuration.html user = www # 运行命令的用户
4 启用supervisor
supervisord -c /etc/supervisor/supervisord.conf # 启动supervisor
supervisorctl # 打开命令行
supervisorctl status # 状态
supervisorctl reload # 重启
supervisorctl stop spider #关闭目标程序
supervisorctl start spider #启动目标程序
supervisorctl shutdown #关闭所有程序
5 开启启动(参考链接 http://www.163py.com/pages/122/130/504/article_index.html )
# vi /etc/init.d/supervisord #!/bin/sh # # /etc/rc.d/init.d/supervisord # # supervisor is a client/server system that # allows its users to monitor and control a # number of processes on UNIX-like operating # systems. # # chkconfig: - 64 36 # description: Supervisor Server # processname: supervisord # Source init functions . /etc/init.d/functions RETVAL=0 pidfile="/tmp/supervisord.pid" lockfile="/tmp/supervisord" start() { echo -n $"Starting $prog: " daemon --pidfile $pidfile /usr/local/bin/supervisord -c /etc/supervisor/supervisord.conf RETVAL=$? echo [ $RETVAL -eq 0 ] && touch ${lockfile} } stop() { echo -n $"Shutting down $prog: " killproc -p ${pidfile} /usr/local/bin/supervisord RETVAL=$? echo if [ $RETVAL -eq 0 ] ; then rm -f ${lockfile} ${pidfile} fi } case "$1" in start) start ;; stop) stop ;; status) /usr/local/bin/supervisorctl status #status $prog ;; restart) stop start ;; *) echo "Usage: $0 {start|stop|restart|status}" ;; esac
5.1 chkconfig --add supervisord
5.2 chkconfig supervisord on
5.3 可以使用service 进行操作start stop restart 操作
结束语
本文有任何错误,或有任何疑问,欢迎留言说明。
网友最新评论