]> git.openstreetmap.org Git - chef.git/commitdiff
Rework cplanet file locations
authorTom Hughes <tom@compton.nu>
Sat, 15 Sep 2018 11:44:51 +0000 (12:44 +0100)
committerTom Hughes <tom@compton.nu>
Sat, 15 Sep 2018 11:51:52 +0000 (12:51 +0100)
cookbooks/cplanet/attributes/default.rb [new file with mode: 0644]
cookbooks/cplanet/recipes/default.rb
cookbooks/cplanet/templates/default/planet-update-file.erb [moved from cookbooks/cplanet/templates/default/update-planet.erb with 77% similarity]
cookbooks/cplanet/templates/default/planet-update.cron.erb [new file with mode: 0644]
cookbooks/cplanet/templates/default/planet-update.erb [new file with mode: 0644]
cookbooks/cplanet/templates/default/planet-update.logrotate.erb [new file with mode: 0644]
cookbooks/cplanet/templates/default/update.erb [deleted file]

diff --git a/cookbooks/cplanet/attributes/default.rb b/cookbooks/cplanet/attributes/default.rb
new file mode 100644 (file)
index 0000000..e1e8c38
--- /dev/null
@@ -0,0 +1 @@
+default[:cplanet][:jobs] = {}
index 074671e7affc8131c5ba40eadde40cfa9ee7a036..1d3b6499c4606de1bf4bd3c8dbc3687589b73499 100644 (file)
 # limitations under the License.
 #
 
-user = "cplanet"
-basedir = "/srv/cplanet"
-planet_source = "https://planet.openstreetmap.org/pbf/planet-latest.osm.pbf"
-
 package %w[
   pyosmium
 ]
 
-directory basedir do
+template "/usr/local/bin/planet-update" do
+  source "planet-update.erb"
   owner "root"
   group "root"
   mode 0o755
 end
 
-%w[bin jobs log].each do |dir|
-  directory "#{basedir}/#{dir}" do
-    owner "root"
-    group "root"
-    mode 0o755
-  end
+template "/usr/local/bin/planet-update-file" do
+  source "planet-update-file.erb"
+  owner "root"
+  group "root"
+  mode 0o755
 end
 
-directory "#{basedir}/planet" do
-  owner user
-  group user
+directory "/var/lib/planet" do
+  owner "planet"
+  group "planet"
   mode 0o755
 end
 
-%w[update update-planet].each do |file|
-  template "#{basedir}/bin/#{file}" do
-    source "#{file}.erb"
-    owner "root"
-    group "root"
-    mode 0o755
-    variables :basedir => basedir, :user => user
-  end
+remote_file "/var/lib/planet/planet.pbf" do
+  action :create_if_missing
+  source "https://planet.openstreetmap.org/pbf/planet-latest.osm.pbf"
+  owner "planet"
+  group "planet"
+  mode 0o644
 end
 
-remote_file "#{basedir}/planet/planet.pbf" do
-  action :create_if_missing
-  source planet_source
-  owner user
-  group user
+template "/etc/cron.d/planet-update" do
+  source "planet-update.cron.erb"
+  owner "root"
+  group "root"
   mode 0o644
 end
 
-cron "update-planet" do
-  hour 1
-  minute 17
-  user "root"
-  command "#{basedir}/bin/update"
+template "/etc/logrotate.d/planet-update" do
+  source "planet-update.logrotate.erb"
+  owner "root"
+  group "root"
+  mode 0o644
 end
similarity index 77%
rename from cookbooks/cplanet/templates/default/update-planet.erb
rename to cookbooks/cplanet/templates/default/planet-update-file.erb
index 6c77eafa60e8a50436cce73a513316a6ed98b6fa..36786e23248fc360c9de3c7add158ad42f1b97d5 100644 (file)
@@ -4,18 +4,18 @@
 
 # setup
 
-PLANETDIR="<%= @basedir %>/planet"
+PLANETDIR="/var/lib/planet"
 PLANETPREV="${PLANETDIR}/planet-previous.pbf"
 PLANETCURR="${PLANETDIR}/planet.pbf"
 PLANETNEW="${PLANETDIR}/planet-new.pbf"
 PLANETTMP="${PLANETDIR}/planet-tmp.pbf"
 
-pyosmium-up-to-date -v -o $PLANETNEW $PLANETCURR
+pyosmium-up-to-date -v -o "$PLANETNEW" "$PLANETCURR"
 retval=$?
 
 while [ $retval -eq 1 ]; do
     mv "$PLANETNEW" "$PLANETTMP"
-    pyosmium-up-to-date -v -o $PLANETNEW $PLANETTMP
+    pyosmium-up-to-date -v -o "$PLANETNEW" "$PLANETTMP"
     retval=$?
     rm "$PLANETTMP"
 done
@@ -28,4 +28,3 @@ fi
 
 mv "$PLANETCURR" "$PLANETPREV"
 mv "$PLANETNEW" "$PLANETCURR"
-
diff --git a/cookbooks/cplanet/templates/default/planet-update.cron.erb b/cookbooks/cplanet/templates/default/planet-update.cron.erb
new file mode 100644 (file)
index 0000000..a12c53e
--- /dev/null
@@ -0,0 +1,3 @@
+# DO NOT EDIT - This file is being maintained by Chef
+
+17 1 * * * planet /usr/local/bin/planet-update
diff --git a/cookbooks/cplanet/templates/default/planet-update.erb b/cookbooks/cplanet/templates/default/planet-update.erb
new file mode 100644 (file)
index 0000000..683214e
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+# DO NOT EDIT - This file is being maintained by Chef
+
+exec > /var/log/planet-update.log 2>&1
+
+echo "Updating planet file..."
+
+runuser -u planet -- /usr/local/bin/planet-update-file
+
+echo "Running jobs..."
+<% node[:cplanet][:jobs].each do |job| -%>
+
+echo "Running '<%= job[:command] %>' as user '<%= job[:user] %>'..."
+
+runuser -u "<%= job[:user] %>" -- "<%= job[:command] %>"
+<% end -%>
+
+echo "Done."
diff --git a/cookbooks/cplanet/templates/default/planet-update.logrotate.erb b/cookbooks/cplanet/templates/default/planet-update.logrotate.erb
new file mode 100644 (file)
index 0000000..a3ca8ac
--- /dev/null
@@ -0,0 +1,5 @@
+/var/log/planet-update.log {
+       compress
+       notifempty
+       missingok
+}
diff --git a/cookbooks/cplanet/templates/default/update.erb b/cookbooks/cplanet/templates/default/update.erb
deleted file mode 100644 (file)
index c1b1b90..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-
-# DO NOT EDIT - This file is being maintained by Chef
-
-USER="<%= @user %>"
-DIR="<%= @basedir %>"
-LOGDIR="${DIR}/log"
-
-# start logging
-
-exec >"${LOGDIR}/$(date +%Y%m%d-%H%M).log" 2>&1
-
-echo "Updating planet file..."
-sudo -u "$USER" "$DIR/bin/update-planet"
-
-echo "Running jobs..."
-if [ -d "$DIR/jobs" ]; then
-    for job in `find "$DIR/jobs" -type f -executable | sort`; do
-        user=`stat '--format=%U' $job`
-        echo "Running '$job' as user '$user'..."
-        su -c "$job" "$user"
-    done
-fi
-
-echo
-echo "Expire old logs..."
-find "${LOGDIR}" -mtime +28 -delete
-
-echo "Done."
-