supervisord的用途:
把不是守护进程的进程变成守护进程
监控它自己启动的进程
可以精确控制进程的状态
supervisord需要python,系统是ubuntu,py版本是2.7.6,要先安装pip:
apt-get update
apt-get install pip
pip install supervisor
问题:
在某些机器上安装pip失败,如下:
root@tanxf:/opt/jdk1.8.0_121# apt-get install pip
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
E: 未发现软件包 pip
root@tanxf:/opt/jdk1.8.0_121# apt-get install aptitude
root@tanxf:/opt/jdk1.8.0_121# aptitude install python-pip
可先装aptitude工具
这个也行:
apt-get install python-setuptools
easy_install pip
......
Installing /usr/local/lib/python2.7/dist-packages/supervisor-3.3.1-nspkg.pth
Installing echo_supervisord_conf script to /usr/local/bin
Installing pidproxy script to /usr/local/bin
Installing supervisorctl script to /usr/local/bin
Installing supervisord script to /usr/local/bin
Successfully installed supervisor meld3
Cleaning up...
centos环境,py版本是2.7.5,用这个:
yum install python-setuptools
easy_install supervisor
安装完成,脚本插入到了/usr/local/bin/目录下(centos会在/usr/bin/目录下 )
root@lq-OptiPlex-755:/usr/local/bin# ll
总用量 8444
drwxr-xr-x 2 root root 4096 3月 17 14:38 ./
drwxr-xr-x 17 root root 4096 3月 7 09:07 ../
-rwxr-xr-x 1 root root 8260272 3月 6 16:12 docker-compose*
-rwxr-xr-x 1 root root 338 3月 17 14:38 echo_supervisord_conf*
-rwxr-xr-x 1 lq lq 358330 7月 28 2016 nmon*
-rwxr-xr-x 1 root root 312 3月 17 14:38 pidproxy*
-rwxr-xr-x 1 root root 322 3月 17 14:38 supervisorctl*
-rwxr-xr-x 1 root root 318 3月 17 14:38 supervisord*
root@lq-OptiPlex-755:/usr/local/bin# echo_supervisord_conf > supervisord.conf
root@lq-OptiPlex-755:/usr/local/bin# ll
总用量 8456
drwxr-xr-x 2 root root 4096 3月 17 14:40 ./
drwxr-xr-x 17 root root 4096 3月 7 09:07 ../
-rwxr-xr-x 1 root root 8260272 3月 6 16:12 docker-compose*
-rwxr-xr-x 1 root root 338 3月 17 14:38 echo_supervisord_conf*
-rwxr-xr-x 1 lq lq 358330 7月 28 2016 nmon*
-rwxr-xr-x 1 root root 312 3月 17 14:38 pidproxy*
-rwxr-xr-x 1 root root 322 3月 17 14:38 supervisorctl*
-rwxr-xr-x 1 root root 318 3月 17 14:38 supervisord*
-rw-r--r-- 1 root root 8658 3月 17 14:40 supervisord.conf
root@lq-OptiPlex-755:/usr/local/bin#
以tomcat为例(/usr/local/apache-tomcat-demo/bin):
在supervisord.conf里加上
[program:tt]
user=root
command=/usr/local/apache-tomcat-demo/bin/catalina.sh run
autostart=true
autorestart=true
stderr_logfile=/usr/local/logs/supervisord/tomcat_err.log
stdout_logfile=/usr/local/logs/supervisord/tomcat_sout.log
environment=JAVA_HOME="/opt/jdk1.7.0_79"
root@lq-OptiPlex-755:/usr/local/bin# supervisord -c ./supervisord.conf
启动程序,可以通过supervisorctl查看状态。(不过失败了,去看下日志调试下)
root@lq-OptiPlex-755:/usr/local/bin# supervisorctl
tt FATAL Exited too quickly (process log may have details)
supervisor> restart tt
tomcattest: ERROR (not running)
tomcattest: ERROR (spawn error)
supervisor> help
default commands (type help
=====================================
add exit open reload restart start tail
avail fg pid remove shutdown status update
clear maintail quit reread signal stop version
supervisor> reload
Really restart the remote supervisord process y/N? y
Restarted supervisord
supervisor> start tt
tt: ERROR (already started)
supervisor> restart tt
tt: stopped
tt: started
supervisor> status
tt RUNNING pid 10180, uptime 0:00:05
调试情况,查看日志时发现
/usr/local/apache-tomcat-demo/bin/catalina.sh: 1: exec: /opt/jdk1.7.0_79 /bin/java: not found
没找到jdk,但是单独启动tomcat是没有问题的,系统环境变量没有问题,可能是supervisord 的环境变量找不到java_home,查看supervisord 配置发现能设置环境变量,加上environment
修改完.conf,先reload,在restart下,查看状态,已经running了。
还有它自带web管理页面,默认配置是注释掉的
[inet_http_server] ; inet (TCP) server disabled by default
port=*:9001
;port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for all iface)
username=user ; (default is no username (open server))
password=123 ; (default is no password (open server))
修改完配置,重新reload下,就可以了