]> git.openstreetmap.org Git - chef.git/commitdiff
Convert gpx-import service to a systemd unit
authorTom Hughes <tom@compton.nu>
Sun, 26 Feb 2017 11:19:41 +0000 (11:19 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 26 Feb 2017 11:19:41 +0000 (11:19 +0000)
cookbooks/web/recipes/gpx.rb
cookbooks/web/templates/default/init.gpx.erb [deleted file]

index 7806530d97f9c216ce2327e71593ce5c1195e2aa..ecaf854dfaf6216c1df4d34c3b24cfef337b4dab 100644 (file)
@@ -53,18 +53,31 @@ git gpx_directory do
   notifies :run, "execute[gpx-import-build]", :immediate
 end
 
   notifies :run, "execute[gpx-import-build]", :immediate
 end
 
-template "/etc/init.d/gpx-import" do
-  source "init.gpx.erb"
-  owner "root"
-  group "root"
-  mode 0o755
-  variables :gpx_directory => gpx_directory,
-            :pid_directory => pid_directory,
-            :log_directory => log_directory,
-            :database_host => node[:web][:database_host],
-            :database_name => "openstreetmap",
-            :database_username => "gpximport",
-            :database_password => db_passwords["gpximport"]
+systemd_service "gpx-import" do
+  description "GPX Import Daemon"
+  after "network.target"
+  type "forking"
+  environment_file "GPX_SLEEP_TIME" => "40",
+                   "GPX_PATH_TRACES" => "/store/rails/gpx/traces",
+                   "GPX_PATH_IMAGES" => "/store/rails/gpx/images",
+                   "GPX_PATH_TEMPLATES" => "#{gpx_directory}/templates/",
+                   "GPX_PGSQL_HOST" => node[:web][:database_host],
+                   "GPX_PGSQL_USER" => "gpximport",
+                   "GPX_PGSQL_PASS" => db_passwords["gpximport"],
+                   "GPX_PGSQL_DB" => "openstreetmap",
+                   "GPX_LOG_FILE" => "#{log_directory}/gpx-import.log",
+                   "GPX_PID_FILE" => "#{pid_directory}/gpx-import.pid",
+                   "GPX_MAIL_SENDER" => "bounces@openstreetmap.org"
+  user "rails"
+  exec_start "#{gpx_directory}/src/gpx-import"
+  exec_reload "/bin/kill -HUP $MAINPID"
+  private_tmp true
+  private_devices true
+  protect_system "full"
+  protect_home true
+  no_new_privileges true
+  restart "on-failure"
+  pid_file "#{pid_directory}/gpx-import.pid"
 end
 
 if %w(database_offline database_readonly gpx_offline).include?(node[:web][:status])
 end
 
 if %w(database_offline database_readonly gpx_offline).include?(node[:web][:status])
@@ -76,6 +89,6 @@ else
     action [:enable, :start]
     supports :restart => true, :reload => true
     subscribes :restart, "execute[gpx-import-build]"
     action [:enable, :start]
     supports :restart => true, :reload => true
     subscribes :restart, "execute[gpx-import-build]"
-    subscribes :restart, "template[/etc/init.d/gpx-import]"
+    subscribes :restart, "systemd_service[gpx-import]"
   end
 end
   end
 end
diff --git a/cookbooks/web/templates/default/init.gpx.erb b/cookbooks/web/templates/default/init.gpx.erb
deleted file mode 100644 (file)
index b186e83..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/bin/bash
-
-export GPX_PROGRAM="<%= @gpx_directory %>/src/gpx-import"
-
-export GPX_SLEEP_TIME="40"
-
-export GPX_PATH_TRACES="/store/rails/gpx/traces"
-export GPX_PATH_IMAGES="/store/rails/gpx/images"
-export GPX_PATH_TEMPLATES="<%= @gpx_directory %>/templates/"
-
-export GPX_PGSQL_HOST="<%= @database_host %>"
-export GPX_PGSQL_USER="<%= @database_username %>"
-export GPX_PGSQL_PASS="<%= @database_password %>"
-export GPX_PGSQL_DB="<%= @database_name %>"
-
-export GPX_LOG_FILE="<%= @log_directory %>/gpx-import.log"
-export GPX_PID_FILE="<%= @pid_directory %>/gpx-import.pid"
-
-export GPX_MAIL_SENDER="bounces@openstreetmap.org"
-
-start() {
-  start-stop-daemon --start --chuid rails --exec $GPX_PROGRAM
-}
-
-stop() {
-  start-stop-daemon --stop --retry 300 --pidfile $GPX_PID_FILE --exec $GPX_PROGRAM
-}
-
-reload() {
-  start-stop-daemon --stop --signal HUP --pidfile $GPX_PID_FILE --exec $GPX_PROGRAM
-}
-
-case "$1" in
-  start)
-    start
-    ;;
-  stop)
-    stop
-    ;;
-  reload)
-    reload
-    ;;
-  restart)
-    stop || exit $?
-    start
-    ;;
-esac