Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for lastaction #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ $ docker run -d \

> Maxage is sixty days and minsize is 100 kilobytes.

## Custom Skript execution
## 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`, `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