diff --git a/README.md b/README.md index 93eba74..2674623 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 ~~~~ diff --git a/logrotate.sh b/logrotate.sh index ca91733..a0ff73b 100755 --- a/logrotate.sh +++ b/logrotate.sh @@ -104,6 +104,8 @@ logrotate_prerotate=${LOGROTATE_PREROTATE_COMMAND:-""} logrotate_postrotate=${LOGROTATE_POSTROTATE_COMMAND:-""} +logrotate_lastaction=${LOGROTATE_LASTACTION_COMMAND:-""} + logrotate_dateformat=${LOGROTATE_DATEFORMAT:-""} resolveSysloggerCommand diff --git a/logrotateConf.sh b/logrotateConf.sh index 4094a4f..d0cf3c0 100755 --- a/logrotateConf.sh +++ b/logrotateConf.sh @@ -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 @@ -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 } diff --git a/logrotateCreateConf.sh b/logrotateCreateConf.sh index d19c2c0..1c7bd7f 100755 --- a/logrotateCreateConf.sh +++ b/logrotateCreateConf.sh @@ -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" }