From 445e3e30dd9f752b4c074d485359bb37db25de2b Mon Sep 17 00:00:00 2001 From: pierreozoux <pierre@ozoux.net> Date: Wed, 29 Apr 2015 14:45:03 +0100 Subject: [PATCH] Fixes logging and restart nicely of HAproxy --- dockerfiles/load-balancer/confd/Dockerfile | 2 +- .../confd/confd/conf.d/crt-list.toml | 3 ++- .../confd/confd/conf.d/haproxy.toml | 3 ++- dockerfiles/load-balancer/haproxy/Dockerfile | 9 ++++++--- dockerfiles/load-balancer/haproxy/run.sh | 20 +++++++++++++++++++ unit-files/haproxy.service | 1 - 6 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 dockerfiles/load-balancer/haproxy/run.sh diff --git a/dockerfiles/load-balancer/confd/Dockerfile b/dockerfiles/load-balancer/confd/Dockerfile index eaeb579..ee149fa 100644 --- a/dockerfiles/load-balancer/confd/Dockerfile +++ b/dockerfiles/load-balancer/confd/Dockerfile @@ -16,7 +16,7 @@ RUN \ chmod +x confd RUN \ - wget https://get.docker.com/builds/Linux/x86_64/docker-1.2.0 -O docker && \ + wget https://get.docker.com/builds/Linux/x86_64/docker-1.5.0 -O docker && \ chmod +x docker ENTRYPOINT ["/confd"] diff --git a/dockerfiles/load-balancer/confd/confd/conf.d/crt-list.toml b/dockerfiles/load-balancer/confd/confd/conf.d/crt-list.toml index ef435f2..26a7ad8 100644 --- a/dockerfiles/load-balancer/confd/confd/conf.d/crt-list.toml +++ b/dockerfiles/load-balancer/confd/confd/conf.d/crt-list.toml @@ -4,4 +4,5 @@ dest = "/etc/haproxy/crt-list" keys = [ "/services" ] -reload_cmd = "/docker kill --signal=\"SIGUSR1\" haproxy" +reload_cmd = "/docker exec haproxy service haproxy reload" + diff --git a/dockerfiles/load-balancer/confd/confd/conf.d/haproxy.toml b/dockerfiles/load-balancer/confd/confd/conf.d/haproxy.toml index d355421..d5c784e 100644 --- a/dockerfiles/load-balancer/confd/confd/conf.d/haproxy.toml +++ b/dockerfiles/load-balancer/confd/confd/conf.d/haproxy.toml @@ -4,4 +4,5 @@ dest = "/etc/haproxy/haproxy.cfg" keys = [ "/services" ] -reload_cmd = "/docker kill --signal=\"SIGUSR1\" haproxy" +reload_cmd = "/docker exec haproxy service haproxy reload" + diff --git a/dockerfiles/load-balancer/haproxy/Dockerfile b/dockerfiles/load-balancer/haproxy/Dockerfile index 392ee88..824ad00 100644 --- a/dockerfiles/load-balancer/haproxy/Dockerfile +++ b/dockerfiles/load-balancer/haproxy/Dockerfile @@ -5,11 +5,14 @@ ENV DEBIAN_FRONTEND noninteractive # Install Haproxy. RUN \ apt-get update && \ - apt-get install -y haproxy && \ + apt-get install -y \ + haproxy \ + rsyslog && \ rm -rf /var/lib/apt/lists/* -ENTRYPOINT ["haproxy"] -CMD ["-f", "/etc/haproxy/haproxy.cfg"] +ADD run.sh /run.sh + +CMD ["/run.sh"] EXPOSE 80 EXPOSE 443 diff --git a/dockerfiles/load-balancer/haproxy/run.sh b/dockerfiles/load-balancer/haproxy/run.sh new file mode 100644 index 0000000..e824876 --- /dev/null +++ b/dockerfiles/load-balancer/haproxy/run.sh @@ -0,0 +1,20 @@ +#!/bin/bash -e + +function cleanup { + /etc/init.d/haproxy stop + /etc/init.d/rsyslog stop + exit 0 +} + +# start haproxy in bg and tail logs out to stdout +/usr/sbin/service rsyslog start +/etc/init.d/haproxy start +tail -f /var/log/syslog & +tail -f /var/log/haproxy.log & + +trap cleanup SIGTERM SIGINT + +while true; do # Iterate to keep job running. + sleep 1 # Don't sleep too long as signals will not be handled during sleep. +done + diff --git a/unit-files/haproxy.service b/unit-files/haproxy.service index bb156a4..3f6c27f 100644 --- a/unit-files/haproxy.service +++ b/unit-files/haproxy.service @@ -17,7 +17,6 @@ ExecStartPre=-/usr/bin/docker rm %p ExecStart=/usr/bin/docker run \ --rm \ --name %p \ - -v /data/runtime/dev/log:/dev/log \ -v /data/runtime/haproxy:/etc/haproxy \ -p 80:80 \ -p 443:443 \ -- GitLab