使用 supervisor在一个 docker container 中开启多个服务

使用 supervisor在一个 docker container 中开启多个服务

1.安装 supervisor

yum install python-setuptools
easy_install supervisor

2.配置文件

vi /etc/supervisord.conf

[supervisord]
nodaemon=true

[program:mysqld]
command=mysqld --user=mysql

[program:tomcat]
command=/software/apache-tomcat-7.0.67/bin/startup.sh

3.启动 supervisor

/usr/bin/supervisord &

报错
tomcat 启动多个:

[root@deb47ba802c7 ~]# /usr/bin/supervisord
/usr/lib/python2.7/site-packages/supervisor-3.2.0-py2.7.egg/supervisor/options.py:296: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
  'Supervisord is running as root and it is searching '
2015-12-26 14:27:03,791 CRIT Supervisor running as root (no user in config file)
2015-12-26 14:27:03,794 INFO supervisord started with pid 710
2015-12-26 14:27:04,797 INFO spawned: 'mysqld' with pid 713
2015-12-26 14:27:04,800 INFO spawned: 'tomcat' with pid 714
2015-12-26 14:27:04,858 INFO exited: tomcat (exit status 0; not expected)
2015-12-26 14:27:06,541 INFO success: mysqld entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2015-12-26 14:27:06,544 INFO spawned: 'tomcat' with pid 762
2015-12-26 14:27:06,621 INFO exited: tomcat (exit status 0; not expected)
2015-12-26 14:27:08,626 INFO spawned: 'tomcat' with pid 788
2015-12-26 14:27:08,685 INFO exited: tomcat (exit status 0; not expected)
2015-12-26 14:27:11,691 INFO spawned: 'tomcat' with pid 814
2015-12-26 14:27:11,707 INFO exited: tomcat (exit status 0; not expected)
2015-12-26 14:27:12,708 INFO gave up: tomcat entered FATAL state, too many start retries too quickly

发现 supervisor 会启动多个 tomcat.参考这里, supervisor 是不能监控守护进程, 那么应该也是无法监控后台启动的程序.

于是修改 supervisor 的配置文件,将 tomcat 改为前台启动catalina.sh run

[supervisord]
nodaemon=true

[program:mysqld]
command=mysqld --user=mysql

[program:tomcat]
command=/software/apache-tomcat-7.0.67/bin/catalina.sh run
2015-12-26 21:46306