无法从Docker容器中使用supervisord启动apache

时间:2014-09-17 18:36:55

标签: apache docker supervisord coreos

我正在运行一个带有CoreOS的Docker容器,它使用最新的Debian作为基础并安装了各种软件包,包括supervisor和apache2。我可以使用以下命令启动并成功运行apache:

# /usr/bin/pidproxy /var/run/apache2.pid /bin/bash -c "source /etc/apache2/envvars && /usr/sbin/apache2 -DFOREGROUND -k start"

但是,当我将此命令粘贴在超级用户配置文件中时:

[program:apache2]
command=/usr/bin/pidproxy /var/run/apache2.pid /bin/bash -c "source /etc/apache2/envvars && /usr/sbin/apache2 -DFOREGROUND -k start"
redirect_stderr=true

并执行此操作:

# supervisorctl start apache2

我回复了这个回复:

apache2: ERROR (abnormal termination)

查看管理程序进程日志文件,我看到了apache2命令的帮助输出,就像它被调用了apache2 -h一样。我不知道为什么当在supervisorctl(以root身份运行)逐字执行时,以root身份执行命令行时执行的命令(ssh进入容器)将无效。

非常感谢正确方向的任何一点。

4 个答案:

答案 0 :(得分:4)

不确定为什么,但在我的选项值中添加引号似乎已经完成了这个技巧,并允许我使用apachectl。必须是具有解释命令的上下文的东西,无论主管正在做什么与从bash提示输入。这是我的工作配置文件:

[program:apache2]
command=apachectl -D "FOREGROUND" -k start
redirect_stderr=true

答案 1 :(得分:1)

这对我有用(使用ubuntu基本图像,但这不重要):

Dockerfile:

# Pull Ubuntu as base image
FROM       dockerfile/ubuntu

...

# Install supervisor to allow starting mutliple processes
RUN        apt-get -y install supervisor && \
           mkdir -p /var/log/supervisor && \
           mkdir -p /etc/supervisor/conf.d
RUN        mkdir /var/log/supervisord
# Add supervisor configuration
ADD        etc/supervisor/supervisor.conf /etc/supervisor.conf

# Install Apache and enable CGI
RUN        apt-get install -y apache2
ADD        etc/apache/000-default.conf /etc/apache2/sites-available/000-default.conf
RUN        a2enmod cgi

....

supervisor.conf

[supervisord]
; supervisord log file
logfile=/var/log/supervisord/supervisord.log

; info, debug, warn, trace 
loglevel=debug

; pidfile location
pidfile=/var/run/supervisord.pid

; run supervisord as a daemon
nodaemon=false 

; number of startup file descriptors    
minfds=1024

; number of process descriptors
minprocs=200 

; default user
user=root 

; where child log files will live
childlogdir=/var/log/supervisord/ 

[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket

; Apache server
[program:apache2]
command=/usr/sbin/apache2ctl -D FOREGROUND
environment=APACHE_LOG_DIR=/var/log/apache2
redirect_stderr=true

答案 2 :(得分:0)

您真的想使用它。如果您不使用pidproxy,则openssl不会杀死所有的孩子。

这还将确保容器在收到SIGTERM时退出,而不是等待SIGKILL。

supervisorctl stop apache

答案 3 :(得分:-2)

在CentOS中,apache被称为httpd而不是apache2 您的主管conf文件需要针对CentOS进行更新

/usr/sbin/httpd是计划地点。

  

[程序:apache2的]

     

command = / usr / bin / pidproxy /var/run/httpd.pid / bin / bash -c“/ usr / sbin / httpd -DFOREGROUND -k start”

     

了redirect_stderr =真

相关问题