forked from linkyard/docker-logrotate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
executable file
·32 lines (28 loc) · 1.17 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/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_PATH:-var/log}/${LOGROTATE_FILE_PATTERN:-*.log} {"
echo " ${LOGROTATE_TRUNCATE:-copytruncate}"
echo " ${LOGROTATE_COMPRESS:-nocompress}"
echo " rotate ${LOGROTATE_ROTATE:-5}"
echo " size ${LOGROTATE_SIZE:-50M}"
echo " postrotate"
echo " ${LOGROTATE_POSTROTATE:-echo 'test'}"
echo " endscript"
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}"