X-Git-Url: https://git.openstreetmap.org/chef.git/blobdiff_plain/932f7a837e84c5c29fd8429a574dd7aea5314b0a..a0cc3b39962e5921f7a79ea35e2591e163148714:/cookbooks/stats/files/default/repack-archived-logs diff --git a/cookbooks/stats/files/default/repack-archived-logs b/cookbooks/stats/files/default/repack-archived-logs new file mode 100644 index 000000000..3b407b066 --- /dev/null +++ b/cookbooks/stats/files/default/repack-archived-logs @@ -0,0 +1,39 @@ +#!/bin/bash +set -e +user=$(whoami) +if [ "$user" != "www-data" ]; + then + echo 'Error: run as www-data' + exit 1 + fi + +if [ -f /tmp/repack-archive-logs.lock ]; then + if [ "$(ps -p `cat /tmp/repack-archive-logs.lock` | wc -l)" -gt 1 ]; then + echo repack-archive-logs process is still running + exit 1 + else + # process not running, but lock file not deleted? + rm /tmp/repack-archive-logs.lock + fi +fi +echo $$ >/tmp/repack-archive-logs.lock + +function signalExitCaught() { + #Clean up in-process repack + if [ "${file}" ]; then + if [ -f "${file}" -a -f "${file%gz}xz" ]; then + echo cleaning up in-process repack ${file%gz}xz + rm ${file%gz}xz + fi + fi + exit 1 +} + +trap signalExitCaught INT QUIT TERM + +for file in $(find /store/logs/ -mtime +60 -type f -name '*.gz'); do + (gzip -dc "${file}" | xz -9e > "${file%gz}xz") && (touch --no-create --reference="${file}" "${file%gz}xz" && rm "${file}") || (rm "${file%gz}xz") +done + +rm /tmp/repack-archive-logs.lock +exit 0