]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/nominatim/templates/default/updater.erb
nominatim: adapt updates to current load
[chef.git] / cookbooks / nominatim / templates / default / updater.erb
index 2c553ad21372ea0640a767493e63ccd19f65ce95..8345205cb74099bf3baae9b42cdf8717efa4aed0 100644 (file)
@@ -2,26 +2,44 @@
 
 # DO NOT EDIT - This file is being maintained by Chef
 
-# Send output to the log
-exec > /var/log/nominatim/update.log 2>&1
-
 # Change to Nominatim directory
-DIR="$( cd "$( dirname "$0" )" && pwd )"
-cd $DIR/..
+cd <%= @bindir %>
+
+num_cpus=`cat /proc/cpuinfo | grep -c processor`
+num_cpus=(($num_cpus - 2))
 
-while true
+while [ ! -f "<%= @update_stop_file %>" ]
 do
+    # Send output to the log (logrotatable)
+    exec >> <%= @logfile %> 2>&1
     starttime=`date +%s`
 
-    ./utils/update.php --no-npi --import-osmosis
+    current_load=`cat /proc/loadavg | cut -f 2 -d ' ' | sed 's:\..*::'`
 
-    # will trigger recompilation if necessary
-    git pull
+    if [[ $current_load -lt $num_cpus ]]
+    then
+        INST=2
+    else
+        INST=1
+    fi
+
+    ./utils/update.php --no-npi --import-osmosis --index-instances $INST
+
+<% if node[:nominatim][:enable_git_updates] -%>
+    pushd <%= @srcdir %>
+    if git fetch origin; then
+      # will trigger recompilation if necessary
+      git merge origin/<%= @branch %>
+    else
+      echo "WARNING: git fetch failed."
+    fi
+    popd
+<% end -%>
 
     # sleep a bit if updates take less than a minute
     endtime=`date +%s`
     elapsed=$((endtime - starttime))
-    if [[ $elapsed < 60 ]]
+    if [[ $elapsed -lt 60 ]]
     then
         sleepy=$((60 - $elapsed))
         echo "Sleeping for ${sleepy}s..."