| #!/bin/bash |
| # |
| # logrotate - scheme |
| # |
| # Copyright 2019 Luigi Santivetti <luigi.santivetti@gmail.com> |
| |
| # Permission is hereby granted, free of charge, to any person obtaining a |
| # copy of this software and associated documentation files (the "Software"), |
| # to deal in the Software without restriction, including without limitation |
| # the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| # and/or sell copies of the Software, and to permit persons to whom the |
| # Software is furnished to do so, subject to the following conditions: |
| |
| # The above copyright notice and this permission notice (including the next |
| # paragraph) shall be included in all copies or substantial portions of the |
| # Software. |
| |
| # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| # ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
| # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| |
| # Credits to: |
| # https://github.com/linkyard/docker-logrotate |
| |
| declare -r dockerfile_t="\ |
| FROM alpine:3.10 |
| |
| RUN set -x \\ |
| && apk add --no-cache logrotate tini tzdata moreutils \\ |
| && rm /etc/logrotate.conf && rm -r /etc/logrotate.d \\ |
| && mv /etc/periodic/daily/logrotate /etc/.logrotate.cronjob |
| |
| # Only missing uid and gid from alpine 3.10 |
| RUN addgroup -g ${_LOGROTATE_OPENSSH_GID_} ${_LOGROTATE_OPENSSH_USER_} && \\ |
| adduser -H -D -u ${_LOGROTATE_OPENSSH_UID_} -G ${_LOGROTATE_OPENSSH_USER_} ${_LOGROTATE_OPENSSH_USER_} |
| |
| COPY entrypoint.sh /entrypoint.sh |
| |
| VOLUME [\"${_LOGROTATE_LOG_CON_D_}\"] |
| |
| ENTRYPOINT [\"tini\", \"-g\", \"--\"] |
| CMD [\"/entrypoint.sh\"]" |
| |
| declare -r logrotate_conf_t="\ |
| ${_LOGROTATE_APACHE_FILE_PATTERN_} { |
| ${_LOGROTATE_TRUNCATE_} |
| ${_LOGROTATE_COMPRESS_} |
| rotate ${_LOGROTATE_ROTATE_} |
| size ${_LOGROTATE_SIZE_} |
| } |
| |
| ${_LOGROTATE_MYSQL_FILE_PATTERN_} { |
| ${_LOGROTATE_TRUNCATE_} |
| ${_LOGROTATE_COMPRESS_} |
| rotate ${_LOGROTATE_ROTATE_} |
| size ${_LOGROTATE_SIZE_} |
| } |
| |
| ${_LOGROTATE_OPENSSH_FILE_PATTERN_} { |
| ${_LOGROTATE_TRUNCATE_} |
| ${_LOGROTATE_COMPRESS_} |
| rotate ${_LOGROTATE_ROTATE_} |
| size ${_LOGROTATE_SIZE_} |
| }" |
| |
| declare -r entrypoint_bang_t="\ |
| #!/bin/sh |
| |
| TS_FORMAT=\"%Y-%m-%dT%H:%M:%S%z \" |
| |
| if [ -e /etc/logrotate.conf ]; then |
| echo \"Using mounted /etc/logrotate.conf:\" | ts \"\${TS_FORMAT}\" |
| else |
| echo \"Using templated /etc/logrotate.conf:\" | ts \"\${TS_FORMAT}\" |
| { |
| echo \"\${LOGROTATE_FILE_PATTERN:-${_LOGROTATE_LOG_CON_D_}/*.log} {\" |
| echo \" \${LOGROTATE_TRUNCATE:-copytruncate}\" |
| echo \" \${LOGROTATE_COMPRESS:-nocompress}\" |
| echo \" rotate \${LOGROTATE_ROTATE:-5}\" |
| echo \" size \${LOGROTATE_SIZE:-5M}\" |
| echo \"}\" |
| } > /etc/logrotate.conf |
| fi |
| ts \"\${TS_FORMAT}\" < /etc/logrotate.conf |
| |
| if [ -d \"/etc/periodic/\${LOGROTATE_CRON:-15min}\" ]; then |
| echo \"using /etc/periodic/\${LOGROTATE_CRON:-15min} cron schedule\" | ts \"\${TS_FORMAT}\" |
| mv /etc/.logrotate.cronjob \"/etc/periodic/\${LOGROTATE_CRON:-15min}/logrotate\" |
| else |
| echo \"assuming \"\${LOGROTATE_CRON:-15min}\" is a cron expression; appending to root's crontab\" | ts \"\${TS_FORMAT}\" |
| echo \"\${LOGROTATE_CRON:-15min} /etc/.logrotate.cronjob\" >> /var/spool/cron/crontabs/root |
| fi |
| |
| # shellcheck disable=SC2086 |
| exec crond -d \${CROND_LOGLEVEL:-7} -f 2>&1 | ts \"\${TS_FORMAT}\"" |