]> git.openstreetmap.org Git - chef.git/blob - cookbooks/nominatim/templates/default/clean-db-nominatim.erb
Sort addresses for stability
[chef.git] / cookbooks / nominatim / templates / default / clean-db-nominatim.erb
1 #!/bin/bash
2 #
3 # DO NOT EDIT - This file is being maintained by Chef
4
5
6 # Cleanup archive directory
7 oldest=`date +%s`
8
9 for fl in <%= @streaming_clients %>; do
10   lastupdate=`wget -O - -q https://${fl}.openstreetmap.org/last_update.php`
11   if [[ "$?" != "0" ]]; then
12     oldest=0
13     break
14   else
15     epoch=`date +%s -d "$lastupdate"`
16     if [[ "$epoch" -lt "$oldest" ]]; then
17         oldest=$epoch
18     fi
19   fi
20 done
21
22
23 if [[ "$oldest" != "0" ]]; then
24     now=`date +%s`
25     timeago=$(( ( $now - $oldest ) / 60 + 180 ))
26     if [[ "$timeago" -lt "180" ]]; then
27         echo "Oldest is in the future, something is wrong."
28     else
29       if [[ "$timeago" -le "720" ]]; then
30           timeago=720
31       fi
32
33       find -L <%= @archive_dir %> -mmin +$timeago -print0 | xargs -0r rm
34     fi
35 fi
36
37 diskfree=`df --output=pcent <%= @archive_dir %> | tail -n 1 | sed s:[^0-9.]::g`
38
39 if [[ "$diskfree" -lt 10 ]]; then
40     echo "WAL archives running out of space. Stopping updates."
41     touch <%= @update_stop_file %>
42 fi