--- /dev/null
+default[:cplanet][:jobs] = {}
# 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
# 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
mv "$PLANETCURR" "$PLANETPREV"
mv "$PLANETNEW" "$PLANETCURR"
-
--- /dev/null
+# DO NOT EDIT - This file is being maintained by Chef
+
+17 1 * * * planet /usr/local/bin/planet-update
--- /dev/null
+#!/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."
--- /dev/null
+/var/log/planet-update.log {
+ compress
+ notifempty
+ missingok
+}
+++ /dev/null
-#!/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."
-