Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supervisor works when call service docker stop? #5137

Closed
tanbt opened this issue Apr 10, 2014 · 4 comments
Closed

Supervisor works when call service docker stop? #5137

tanbt opened this issue Apr 10, 2014 · 4 comments

Comments

@tanbt
Copy link

tanbt commented Apr 10, 2014

Hi everyone,

I'm trying to manage processes inside a container using supervisor.

I expected supervisor was able to foward all SIGTERM to it's sub-processes (apache, memcache, mysql...) .

With my Dockerfile below, supervisord run with PID 1 and it managed all its sub-processes. When I stop the running container, all sub-processes shut down probably with SIGTERM in their logs (e.g: /var/log/apache2/error.log).

The problem is when I restart docker service, I've seen sub-processes don't receive SIGTERM, they don't clean their pid files too.

Anyone in my case? Is that the way supervisor works, or because of my wrong configuration? Any other ways to restart docker service with all sub-processes shutdown properly?

Thank you.

FROM ubuntu:12.04

MAINTAINER trungtanbui@gmail.com

RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get upgrade -y

RUN apt-get install -y supervisor

RUN touch  /etc/supervisor/conf.d/supervisord.conf && \
    echo "[supervisord]" >> /etc/supervisor/conf.d/supervisord.conf && \
    echo "nodaemon=true" >> /etc/supervisor/conf.d/supervisord.conf

RUN apt-get install -y memcached apache2 htop

# start memcached
RUN touch /etc/supervisor/conf.d/memcached.conf && \
    echo "[program:memcache]" >> /etc/supervisor/conf.d/memcached.conf && \
    echo "command=/usr/bin/memcached -m 64 -p 11211 -u memcache -l 127.0.0.1 -DFOREGROUND" >> /etc/supervisor/conf.d/memcached.conf && \
    echo "autostart=true" >> /etc/supervisor/conf.d/memcached.conf && \
    echo "autorestart=true" >> /etc/supervisor/conf.d/memcached.conf

# start apache2
RUN touch /etc/supervisor/conf.d/apache2.conf && \
    echo "[program:apache2]" >> /etc/supervisor/conf.d/apache2.conf && \
    echo 'command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND"' >> /etc/supervisor/conf.d/apache2.conf && \
    echo "autostart=true" >> /etc/supervisor/conf.d/apache2.conf && \
    echo "autorestart=true" >> /etc/supervisor/conf.d/apache2.conf

EXPOSE 8080:80

CMD ["/usr/bin/supervisord"]
@tanbt
Copy link
Author

tanbt commented Apr 10, 2014

I've done another test to detect does docker send signal to process PID=1 when stop.
This is my script, running as PID=1, which will catch all received signal and write to log file.

#!/bin/bash
# Program to print a text file with headers and footers
TEMP_FILE=/home/aprintfile.txt

my_func(){
    echo $(date) >> $TEMP_FILE
    echo $1 >> $TEMP_FILE
}

trap_with_arg() {
    func="$1" ; shift
    for sig ; do
        trap "$func $sig" "$sig"
    done
}

trap_with_arg 'my_func' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64

echo $1 >> $TEMP_FILE

echo -n "Hang on! Stop now? [y/n]: "
read
if [ "$REPLY" = "y" ]; then
    echo "stop by GUI" >> $TEMP_FILE
    exit;
fi
echo "end of script" >> $TEMP_FILE
exit

With "docker stop my_container", log file properly catch:

Thu Apr 10 04:42:24 UTC 2014
15

With "sudo service docker restart", log file catch:

Thu Apr 10 04:45:05 UTC 2014
15
Thu Apr 10 04:45:10 UTC 2014
18
Thu Apr 10 04:45:10 UTC 2014
1
end of script
exit code:
0

Any idea about which happen?

@unclejack
Copy link
Contributor

ping @creack

@sumkincpp
Copy link

For similar configuration with ubuntu:14.04 image and latest docker (1.4.1) I've got it working.
Supervisord was running in foreground(nodaemon=true).

@trungtan haven't you resolved that issue? I've tried to build your Dockerfile but have no success due to broken ubuntu updates.

@jessfraz
Copy link
Contributor

this should work on the latest version of docker, I have noticed a few images on hub using supervisord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants