简体   繁体   中英

Can't start apache with supervisord from a Docker container

I'm running a Docker container with CoreOS which uses Debian latest as a base and has various packages installed including supervisor and apache2. I can start and successfully run apache using the following command:

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

However, when I stick this command in a supervisor config file:

[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

and do this:

# supervisorctl start apache2

I get back this response:

apache2: ERROR (abnormal termination)

Looking at the supervisor process log file I see the help output from the apache2 command, as if it had been called like so apache2 -h . I have no idea why a command which runs when executed on the command line as root (ssh into the container) would not work when verbatim executed by supervisorctl (run as root).

Any point in the right direction would be greatly appreciated.

Not really sure why, but adding quotes to my option values seems to have done the trick, and allowed me to use apachectl. Must be something with the context in which the command is interpreted, whatever supervisor is doing vs input from a bash prompt. Here's my working config file:

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

This is what works for me (using an ubuntu base image, but that should not matter):

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

You really want to use this. If you don't use pidproxy, a supervisorctl stop apache will not kill all it's children.

This will also make sure that the container will quit when it gets a SIGTERM instead of waiting for a SIGKILL.

[program:apache]
command=/usr/bin/pidproxy /var/run/apache2/apache2.pid /bin/bash -c "/usr/sbin/apache2ctl -D FOREGROUND"
autorestart=true

In CentOS apache is Called httpd not apache2 Your supervisor conf file will need to be updated for CentOS

/usr/sbin/httpd is the program location.

[program:apache2]

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

redirect_stderr=true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM