]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/recipes/gpx.rb
Merge remote-tracking branch 'github/pull/165'
[chef.git] / cookbooks / web / recipes / gpx.rb
1 #
2 # Cookbook Name:: web
3 # Recipe:: gpx
4 #
5 # Copyright 2011, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 include_recipe "web::base"
21
22 db_passwords = data_bag_item("db", "passwords")
23
24 package %w[
25   gcc
26   make
27   pkg-config
28   libarchive-dev
29   libbz2-dev
30   libexpat1-dev
31   libgd2-noxpm-dev
32   libmemcached-dev
33   libpq-dev
34   zlib1g-dev
35 ]
36
37 gpx_directory = "#{node[:web][:base_directory]}/gpx-import"
38 pid_directory = node[:web][:pid_directory]
39 log_directory = node[:web][:log_directory]
40
41 execute "gpx-import-build" do
42   action :nothing
43   command "make DB=postgres"
44   cwd "#{gpx_directory}/src"
45   user "rails"
46   group "rails"
47 end
48
49 git gpx_directory do
50   action :sync
51   repository "https://git.openstreetmap.org/public/gpx-import.git"
52   revision "live"
53   user "rails"
54   group "rails"
55   notifies :run, "execute[gpx-import-build]", :immediate
56 end
57
58 systemd_service "gpx-import" do
59   description "GPX Import Daemon"
60   after "network.target"
61   type "forking"
62   environment_file "GPX_SLEEP_TIME" => "40",
63                    "GPX_PATH_TRACES" => "/store/rails/gpx/traces",
64                    "GPX_PATH_IMAGES" => "/store/rails/gpx/images",
65                    "GPX_PATH_TEMPLATES" => "#{gpx_directory}/templates/",
66                    "GPX_PGSQL_HOST" => node[:web][:database_host],
67                    "GPX_PGSQL_USER" => "gpximport",
68                    "GPX_PGSQL_PASS" => db_passwords["gpximport"],
69                    "GPX_PGSQL_DB" => "openstreetmap",
70                    "GPX_LOG_FILE" => "#{log_directory}/gpx-import.log",
71                    "GPX_PID_FILE" => "#{pid_directory}/gpx-import.pid",
72                    "GPX_MAIL_SENDER" => "bounces@openstreetmap.org"
73   user "rails"
74   exec_start "#{gpx_directory}/src/gpx-import"
75   exec_reload "/bin/kill -HUP $MAINPID"
76   private_tmp true
77   private_devices true
78   protect_system "full"
79   protect_home true
80   restart "on-failure"
81   pid_file "#{pid_directory}/gpx-import.pid"
82 end
83
84 if %w[database_offline database_readonly gpx_offline].include?(node[:web][:status])
85   service "gpx-import" do
86     action :stop
87   end
88 else
89   service "gpx-import" do
90     action [:enable, :start]
91     supports :restart => true, :reload => true
92     subscribes :restart, "execute[gpx-import-build]"
93     subscribes :restart, "systemd_service[gpx-import]"
94   end
95 end