Skip to content

Commit

Permalink
FIX: force all sub processes to stop on TERM, wait for them to finish
Browse files Browse the repository at this point in the history
This works around docker bug where containers will not stop
  • Loading branch information
SamSaffron committed Jan 26, 2016
1 parent 8877f99 commit d821539
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion image/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ RUN echo "debconf debconf/frontend select Teletype" | debconf-set-selections &&\
apt-get -y install build-essential git curl wget \
libxslt-dev libcurl4-openssl-dev \
libssl-dev libyaml-dev libtool \
libxml2-dev gawk \
libxml2-dev gawk parallel \
postgresql-9.3 postgresql-client-9.3 \
postgresql-contrib-9.3 libpq-dev libreadline-dev \
nginx language-pack-en sudo cron anacron \
Expand Down
19 changes: 18 additions & 1 deletion image/base/boot
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@

# we use this to boot up cause runit will not handle TERM and will not exit when done

shutdown() {
echo Shutting Down
/etc/runit/3
ls /etc/service | SHELL=/bin/sh parallel sv force-stop {}
kill -HUP $RUNSVDIR
wait $RUNSVDIR

# give stuff a bit of time to finish
sleep 0.1

ORPHANS=`ps -eo pid | grep -v PID | tr -d ' ' | grep -v '^1$'`
SHELL=/bin/bash parallel 'timeout 5 /bin/bash -c "kill {} && wait {}" || kill -9 {}' ::: $ORPHANS 2> /dev/null
exit
}

/etc/runit/1
/etc/runit/2&
RUNSVDIR=$!
echo "Started runsvdir, PID is $RUNSVDIR"
trap "echo Shutting Down && /etc/runit/3 && kill -HUP $RUNSVDIR && wait $RUNSVDIR" SIGTERM SIGHUP
trap shutdown SIGTERM SIGHUP
wait $RUNSVDIR

shutdown

0 comments on commit d821539

Please sign in to comment.