Skip to content

Commit

Permalink
Add support for lastaction
Browse files Browse the repository at this point in the history
  • Loading branch information
yizeng committed Sep 8, 2021
1 parent fdab0ab commit c70f099
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ $ docker run -d \
## Custom Script execution

Sometimes it is necessary to signal the process in order to start logrotation or stop logrotation. You
can do this with the environment variables `LOGROTATE_PREROTATE_COMMAND` and `LOGROTATE_POSTROTATE_COMMAND`.
can do this with the environment variables `LOGROTATE_PREROTATE_COMMAND` and , `LOGROTATE_POSTROTATE_COMMAND` and `LOGROTATE_LASTACTION_COMMAND`.

Example:

Expand All @@ -382,6 +382,7 @@ $ docker run -d \
-e "LOGS_DIRECTORIES=/var/lib/docker/containers /var/log/docker" \
-e "LOGROTATE_PREROTATE_COMMAND=/usr/bin/yourscript.sh" \
-e "LOGROTATE_POSTROTATE_COMMAND=/usr/bin/killall -HUP httpd" \
-e "LOGROTATE_LASTACTION_COMMAND=/usr/bin/lastscript.sh" \
blacklabelops/logrotate
~~~~

Expand Down
2 changes: 2 additions & 0 deletions logrotate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ logrotate_prerotate=${LOGROTATE_PREROTATE_COMMAND:-""}

logrotate_postrotate=${LOGROTATE_POSTROTATE_COMMAND:-""}

logrotate_lastaction=${LOGROTATE_LASTACTION_COMMAND:-""}

logrotate_dateformat=${LOGROTATE_DATEFORMAT:-""}

resolveSysloggerCommand
Expand Down
6 changes: 6 additions & 0 deletions logrotateConf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function createLogrotateConfigurationEntry() {
local conf_maxage="${12}"
local conf_prerotate="${13}"
local conf_postrotate="${14}"
local conf_lastaction="${15}"
local new_log=
new_log=${file}" {"
if [ "$file_user" != "UNKNOWN" ] && [ "$file_owner" != "UNKNOWN" ]; then
Expand Down Expand Up @@ -58,6 +59,11 @@ function createLogrotateConfigurationEntry() {
new_log=${new_log}"\n\t${conf_postrotate}"
new_log=${new_log}"\n endscript"
fi
if [ -n "${conf_lastaction}" ]; then
new_log=${new_log}"\n lastaction"
new_log=${new_log}"\n\t${conf_lastaction}"
new_log=${new_log}"\n endscript"
fi
new_log=${new_log}"\n}"
echo -e $new_log
}
Expand Down
2 changes: 1 addition & 1 deletion logrotateCreateConf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function handleSingleFile() {
local singleFile="$1"
local file_owner_user=$(stat -c %U ${singleFile})
local file_owner_group=$(stat -c %G ${singleFile})
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}")
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}" "${logrotate_lastaction}")
echo "Inserting new ${singleFile} to /usr/bin/logrotate.d/logrotate.conf"
insertConfigurationEntry "$new_logrotate_entry" "/usr/bin/logrotate.d/logrotate.conf"
}
Expand Down

0 comments on commit c70f099

Please sign in to comment.