Skip to content

Commit

Permalink
Made docker-gen being run once just before logrotate, fixed logrotate…
Browse files Browse the repository at this point in the history
… config and moved some stuff to env vars
  • Loading branch information
michaloo committed Aug 22, 2014
1 parent c276b02 commit 288cbf3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
11 changes: 9 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
2 changes: 0 additions & 2 deletions Procfile

This file was deleted.

2 changes: 2 additions & 0 deletions crane.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 * * * * *"
12 changes: 5 additions & 7 deletions logrotate.tmpl
Original file line number Diff line number Diff line change
@@ -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 }}

15 changes: 5 additions & 10 deletions start
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 288cbf3

Please sign in to comment.