Skip to content

Commit 744e0d9

Browse files
committed
feat: modernize image and change scheduler
1 parent c17cb7b commit 744e0d9

File tree

7 files changed

+18
-22
lines changed

7 files changed

+18
-22
lines changed

Containerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ ENV CONTAINER_UID=${CONTAINER_UID} \
1111
# Install logrotate and go-cron - also create logrotate user and group
1212
RUN addgroup -g $CONTAINER_GID logrotate && \
1313
adduser -u $CONTAINER_UID -G logrotate -h /usr/bin/logrotate.d -s /bin/bash -S logrotate && \
14-
apk add --update tar gzip wget tzdata && \
14+
apk add --update bash tar gzip tzdata tini && \
1515
if [ "${LOGROTATE_VERSION}" = "latest" ]; \
1616
then apk add logrotate ; \
1717
else apk add "logrotate=${LOGROTATE_VERSION}"; \
1818
fi && \
1919
mkdir -p /usr/bin/logrotate.d && \
20-
wget --no-check-certificate -O /tmp/go-cron.tar.gz https://github.com/michaloo/go-cron/releases/download/v0.0.2/go-cron.tar.gz && \
21-
tar xvf /tmp/go-cron.tar.gz -C /usr/bin && \
22-
apk del wget && \
2320
rm -rf /var/cache/apk/* && rm -rf /tmp/*
2421

22+
# Install ofelia for cronjob scheduling
23+
COPY --from=docker.io/mcuadros/ofelia:0.3 /usr/bin/ofelia /usr/bin/ofelia
24+
2525
# Available environment variables for this container
2626
ENV LOGROTATE_OLDDIR= \
2727
LOGROTATE_COMPRESSION= \

logrotate.d/logrotate-config.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
#
3-
# Helper functions for manipulating logrotate configurationsfile
3+
# Helper functions for manipulating logrotate configuration file
44

55
function createLogrotateConfigurationEntry() {
66
local file="$1"
@@ -18,6 +18,7 @@ function createLogrotateConfigurationEntry() {
1818
local conf_prerotate="${13}"
1919
local conf_postrotate="${14}"
2020
local new_log=
21+
2122
new_log=${file}" {"
2223
if [ "$file_user" != "UNKNOWN" ] && [ "$file_owner" != "UNKNOWN" ]; then
2324
new_log=${new_log}"\n su ${file_user} ${file_owner}"

logrotate.d/logrotate-create-config.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
#!/bin/bash
22
#
3-
# Creation of Logfile
3+
# Creation of logrotate configuration file based on environment variables
44

5+
# Logfile Crawling
56
function handleSingleFile() {
67
local singleFile="$1"
78
local file_owner_user=$(stat -c %U ${singleFile})
89
local file_owner_group=$(stat -c %G ${singleFile})
910
local new_logrotate_entry=$(createLogrotateConfigurationEntry "${singleFile}" "${file_owner_user}" "${file_owner_group}" "${logrotate_copies}" "${logrotate_logfile_compression}" "${logrotate_logfile_compression_delay}" "${logrotate_mode}" "${logrotate_interval}" "${logrotate_size}" "${logrotate_dateformat}" "${logrotate_minsize}" "${logrotate_maxage}" "${logrotate_prerotate}" "${logrotate_postrotate}")
11+
1012
echo "Inserting new ${singleFile} to /usr/bin/logrotate.d/logrotate.conf"
1113
insertConfigurationEntry "$new_logrotate_entry" "/usr/bin/logrotate.d/logrotate.conf"
1214
}
1315

14-
# ----- Logfile Crawling ------
15-
1616
log_dirs=""
17-
1817
if [ -n "${LOGS_DIRECTORIES}" ]; then
1918
log_dirs=${LOGS_DIRECTORIES}
2019
else
@@ -23,7 +22,6 @@ fi
2322

2423
logs_ending="log"
2524
LOGS_FILE_ENDINGS_INSTRUCTION=""
26-
2725
if [ -n "${LOG_FILE_ENDINGS}" ]; then
2826
logs_ending=${LOG_FILE_ENDINGS}
2927
fi
@@ -63,10 +61,8 @@ do
6361
done
6462
done
6563

66-
# ----- Take all Log in Subfolders ------
67-
64+
# Take all log files in subfolder's
6865
all_log_dirs=""
69-
7066
if [ -n "${ALL_LOGS_DIRECTORIES}" ]; then
7167
all_log_dirs=${ALL_LOGS_DIRECTORIES}
7268
fi

logrotate.d/logrotate.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ EOF
2424
readonly logrotate_logstatus=${LOGROTATE_STATUSFILE:-"/logrotate-status/logrotate.status"}
2525

2626
logrotate_olddir=""
27-
2827
function resolveOldDir() {
2928
if [ -n "${LOGROTATE_OLDDIR}" ]; then
3029
logrotate_olddir="olddir "${LOGROTATE_OLDDIR}
@@ -69,41 +68,35 @@ logrotate_interval=${LOGROTATE_INTERVAL:-""}
6968
logrotate_copies=${LOGROTATE_COPIES:-"5"}
7069

7170
logrotate_size=""
72-
7371
function resolveLogrotateSize() {
7472
if [ -n "${LOGROTATE_SIZE}" ]; then
7573
logrotate_size="size "${LOGROTATE_SIZE}
7674
fi
7775
}
7876

7977
logrotate_minsize=""
80-
8178
function resolveMinSize() {
8279
if [ -n "${LOGROTATE_MINSIZE}" ]; then
8380
logrotate_minsize="minsize ${LOGROTATE_MINSIZE}"
8481
fi
8582
}
8683

8784
logrotate_maxage=""
88-
8985
function resolveMaxAge() {
9086
if [ -n "${LOGROTATE_MAXAGE}" ]; then
9187
logrotate_maxage="maxage ${LOGROTATE_MAXAGE}"
9288
fi
9389
}
9490

9591
logrotate_autoupdate=true
96-
9792
function resolveLogrotateAutoupdate() {
9893
if [ -n "${LOGROTATE_AUTOUPDATE}" ]; then
9994
logrotate_autoupdate="$(echo ${LOGROTATE_AUTOUPDATE,,})"
10095
fi
10196
}
10297

10398
logrotate_prerotate=${LOGROTATE_PREROTATE_COMMAND:-""}
104-
10599
logrotate_postrotate=${LOGROTATE_POSTROTATE_COMMAND:-""}
106-
107100
logrotate_dateformat=${LOGROTATE_DATEFORMAT:-""}
108101

109102
resolveSysloggerCommand

logrotate.d/update-logrotate.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ set -e
99
source /usr/bin/logrotate.d/logrotate.sh
1010
source /usr/bin/logrotate.d/logrotate-config.sh
1111

12-
resetConfigurationFile
1312

14-
#Create Logrotate Conf
13+
# Reset and then regenerate logrotate config
14+
resetConfigurationFile
1515
source /usr/bin/logrotate.d/logrotate-create-config.sh

ofelia/schedule-autoupdate.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[job-local "logrotate-with-autoupdate"]
2+
schedule = @every 15s
3+
command = touch test.txt

ofelia/schedule-standard.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[job-local "logrotate"]
2+
schedule = @every 15s
3+
command = touch test.txt

0 commit comments

Comments
 (0)