]> git.openstreetmap.org Git - chef.git/blob - cookbooks/stats/files/default/repack-archived-logs
Allow % in local parts for locally submitted mail
[chef.git] / cookbooks / stats / files / default / repack-archived-logs
1 #!/bin/bash
2 set -e
3 user=$(whoami)
4 if [ "$user" != "www-data" ];
5         then
6                 echo 'Error: run as www-data'
7                 exit 1
8         fi
9
10 if [ -f /tmp/repack-archive-logs.lock ]; then
11         if [ "$(ps -p `cat /tmp/repack-archive-logs.lock` | wc -l)" -gt 1 ]; then
12                 echo repack-archive-logs process is still running
13                 exit 1
14         else
15                 # process not running, but lock file not deleted?
16                 rm /tmp/repack-archive-logs.lock
17         fi
18 fi
19 echo $$ >/tmp/repack-archive-logs.lock
20
21 function signalExitCaught() {
22  #Clean up in-process repack
23  if [ "${file}" ]; then
24    if [ -f "${file}" -a -f "${file%gz}xz" ]; then
25      echo cleaning up in-process repack ${file%gz}xz
26      rm ${file%gz}xz
27    fi
28  fi 
29  exit 1
30 }
31
32 trap signalExitCaught INT QUIT TERM
33
34 for file in $(find /store/logs/ -mtime +60 -type f -name '*.gz'); do
35     (gzip -dc "${file}" | xz -9e > "${file%gz}xz") && (touch --no-create --reference="${file}" "${file%gz}xz" && rm "${file}") || (rm "${file%gz}xz")
36 done
37
38 rm /tmp/repack-archive-logs.lock
39 exit 0