blob: 6cb8cf0a30cc1856263c21125c2e22b9e970d357 [file] [log] [blame]
Luigi Santivettib77f7022020-11-08 01:04:55 +00001#!/bin/bash
2#
3# logrotate - scheme
4#
5# Copyright 2019 Luigi Santivetti <luigi.santivetti@gmail.com>
6
7# Permission is hereby granted, free of charge, to any person obtaining a
8# copy of this software and associated documentation files (the "Software"),
9# to deal in the Software without restriction, including without limitation
10# the rights to use, copy, modify, merge, publish, distribute, sublicense,
11# and/or sell copies of the Software, and to permit persons to whom the
12# Software is furnished to do so, subject to the following conditions:
13
14# The above copyright notice and this permission notice (including the next
15# paragraph) shall be included in all copies or substantial portions of the
16# Software.
17
18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21# ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25# Credits to:
26# https://github.com/linkyard/docker-logrotate
27
28declare -r dockerfile_t="\
29FROM alpine:3.10
30
31RUN set -x \\
32 && apk add --no-cache logrotate tini tzdata moreutils \\
33 && rm /etc/logrotate.conf && rm -r /etc/logrotate.d \\
34 && mv /etc/periodic/daily/logrotate /etc/.logrotate.cronjob
35
36# Only missing uid and gid from alpine 3.10
37RUN addgroup -g ${_LOGROTATE_OPENSSH_GID_} ${_LOGROTATE_OPENSSH_USER_} && \\
38 adduser -H -D -u ${_LOGROTATE_OPENSSH_UID_} -G ${_LOGROTATE_OPENSSH_USER_} ${_LOGROTATE_OPENSSH_USER_}
39
40COPY entrypoint.sh /entrypoint.sh
41
42VOLUME [\"${_LOGROTATE_LOG_CON_D_}\"]
43
44ENTRYPOINT [\"tini\", \"-g\", \"--\"]
45CMD [\"/entrypoint.sh\"]"
46
47declare -r logrotate_conf_t="\
48${_LOGROTATE_APACHE_FILE_PATTERN_} {
49 ${_LOGROTATE_TRUNCATE_}
50 ${_LOGROTATE_COMPRESS_}
51 rotate ${_LOGROTATE_ROTATE_}
52 size ${_LOGROTATE_SIZE_}
53}
54
55${_LOGROTATE_MYSQL_FILE_PATTERN_} {
56 ${_LOGROTATE_TRUNCATE_}
57 ${_LOGROTATE_COMPRESS_}
58 rotate ${_LOGROTATE_ROTATE_}
59 size ${_LOGROTATE_SIZE_}
60}
61
62${_LOGROTATE_OPENSSH_FILE_PATTERN_} {
63 ${_LOGROTATE_TRUNCATE_}
64 ${_LOGROTATE_COMPRESS_}
65 rotate ${_LOGROTATE_ROTATE_}
66 size ${_LOGROTATE_SIZE_}
67}"
68
69declare -r entrypoint_bang_t="\
70#!/bin/sh
71
72TS_FORMAT=\"%Y-%m-%dT%H:%M:%S%z \"
73
74if [ -e /etc/logrotate.conf ]; then
75 echo \"Using mounted /etc/logrotate.conf:\" | ts \"\${TS_FORMAT}\"
76else
77 echo \"Using templated /etc/logrotate.conf:\" | ts \"\${TS_FORMAT}\"
78 {
79 echo \"\${LOGROTATE_FILE_PATTERN:-${_LOGROTATE_LOG_CON_D_}/*.log} {\"
80 echo \" \${LOGROTATE_TRUNCATE:-copytruncate}\"
81 echo \" \${LOGROTATE_COMPRESS:-nocompress}\"
82 echo \" rotate \${LOGROTATE_ROTATE:-5}\"
83 echo \" size \${LOGROTATE_SIZE:-5M}\"
84 echo \"}\"
85 } > /etc/logrotate.conf
86fi
87ts \"\${TS_FORMAT}\" < /etc/logrotate.conf
88
89if [ -d \"/etc/periodic/\${LOGROTATE_CRON:-15min}\" ]; then
90 echo \"using /etc/periodic/\${LOGROTATE_CRON:-15min} cron schedule\" | ts \"\${TS_FORMAT}\"
91 mv /etc/.logrotate.cronjob \"/etc/periodic/\${LOGROTATE_CRON:-15min}/logrotate\"
92else
93 echo \"assuming \"\${LOGROTATE_CRON:-15min}\" is a cron expression; appending to root's crontab\" | ts \"\${TS_FORMAT}\"
94 echo \"\${LOGROTATE_CRON:-15min} /etc/.logrotate.cronjob\" >> /var/spool/cron/crontabs/root
95fi
96
97# shellcheck disable=SC2086
98exec crond -d \${CROND_LOGLEVEL:-7} -f 2>&1 | ts \"\${TS_FORMAT}\""