From 288cbf3d42bd30c43d0f9d1f1d3e23e43455fd03 Mon Sep 17 00:00:00 2001 From: michaloo Date: Fri, 22 Aug 2014 15:37:34 +0200 Subject: [PATCH] Made docker-gen being run once just before logrotate, fixed logrotate config and moved some stuff to env vars --- Dockerfile | 11 +++++++++-- Procfile | 2 -- crane.yml | 2 ++ logrotate.tmpl | 12 +++++------- start | 15 +++++---------- 5 files changed, 21 insertions(+), 21 deletions(-) delete mode 100644 Procfile diff --git a/Dockerfile b/Dockerfile index 26d8b9f..3a4855a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,14 +22,21 @@ RUN curl -sL https://github.com/michaloo/go-cron/releases/download/v0.0.2/go-cro ADD . /app WORKDIR /app -# clear logrotate ubuntu installation and enable debug information +# clear logrotate ubuntu installation and modify logrotate script +# add docker-gen execution and enable debug mode RUN rm /etc/logrotate.d/* && \ - sed -i -e 's/^\/usr\/sbin\/logrotate.*/\/usr\/sbin\/logrotate \-v \/etc\/logrotate.conf/' /etc/cron.daily/logrotate + sed -i \ + -e 's/^\/usr\/sbin\/logrotate.*/\/usr\/sbin\/logrotate \-v \/etc\/logrotate.conf/' \ + -e '/\#\!\/bin\/sh/a /usr/local/bin/docker-gen /root/logrotate.tmpl /etc/logrotate.d/docker' \ + /etc/cron.daily/logrotate # set default configuration ENV DOCKER_HOST unix:///var/run/docker.sock ENV DOCKER_DIR /var/lib/docker/ ENV GOCRON_SCHEDULER 0 0 * * * * +ENV LOGROTATE_MODE daily +ENV LOGROTATE_ROTATE 3 +ENV LOGROTATE_SIZE 512M ENTRYPOINT [ "/bin/bash" ] CMD [ "/app/start" ] diff --git a/Procfile b/Procfile deleted file mode 100644 index 566472b..0000000 --- a/Procfile +++ /dev/null @@ -1,2 +0,0 @@ -logrotate: /usr/local/bin/go-cron "$GOCRON_SCHEDULER" /etc/cron.daily/logrotate -dockergen: /usr/local/bin/docker-gen -watch /app/logrotate.tmpl /etc/logrotate.d/docker diff --git a/crane.yml b/crane.yml index d884de8..90aa62c 100644 --- a/crane.yml +++ b/crane.yml @@ -21,3 +21,5 @@ containers: - "/var/run/docker.sock:/var/run/docker.sock" - "/var/lib/docker:/var/lib/docker" detach: true + env: + - "GOCRON_SCHEDULER=0 * * * * *" diff --git a/logrotate.tmpl b/logrotate.tmpl index 25b6950..7241e21 100644 --- a/logrotate.tmpl +++ b/logrotate.tmpl @@ -1,14 +1,12 @@ {{ range $index, $value := $ }} -/var/lib/docker/containers/{{ $value.ID }}/{{ $value.ID }}-json.log +/var/lib/docker/containers/{{ $value.ID }}/{{ $value.ID }}-json.log{{ end }} { - daily + {{LOGROTATE_MODE}} missingok - rotate 3 - size 512M + rotate {{LOGROTATE_ROTATE}} + size {{LOGROTATE_SIZE}} compress notifempty - # create 644 root root - copy copytruncate } -{{ end }} + diff --git a/start b/start index b528b26..180e9d2 100644 --- a/start +++ b/start @@ -1,14 +1,9 @@ #!/bin/bash -# using sed to strip color codes from forego output -#exec /usr/local/bin/forego start | sed -r "s:\x1B\[[0-9;]*[mK]::g" +sed -e 's/{{LOGROTATE_MODE}}/'"$LOGROTATE_MODE"'/' \ + -e 's/{{LOGROTATE_ROTATE}}/'"$LOGROTATE_ROTATE"'/' \ + -e 's/{{LOGROTATE_SIZE}}/'"$LOGROTATE_SIZE"'/' \ + /app/logrotate.tmpl > /root/logrotate.tmpl -set -m +exec /usr/local/bin/go-cron "$GOCRON_SCHEDULER" /etc/cron.daily/logrotate -trap 'kill $(jobs -p)' EXIT -trap "exit" CHLD - -/usr/local/bin/docker-gen -watch /app/logrotate.tmpl /etc/logrotate.d/docker & -/usr/local/bin/go-cron "$GOCRON_SCHEDULER" /etc/cron.daily/logrotate & - -wait