]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/recipes/cgimap.rb
Don't use ||= in attributes files as it doesn't work
[chef.git] / cookbooks / web / recipes / cgimap.rb
1 #
2 # Cookbook Name:: web
3 # Recipe:: cgimap
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 #     http://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 "tools"
21 include_recipe "web::base"
22
23 db_passwords = data_bag_item("db", "passwords")
24
25 package "gcc"
26 package "make"
27 package "autoconf"
28 package "automake"
29 package "libfcgi-dev"
30 package "libxml2-dev"
31 package "libmemcached-dev"
32 package "libboost-regex-dev"
33 package "libboost-program-options-dev"
34 package "libboost-date-time-dev"
35 package "libpqxx3-dev"
36 package "zlib1g-dev"
37
38 cgimap_directory = "#{node[:web][:base_directory]}/cgimap"
39 pid_directory = node[:web][:pid_directory]
40 log_directory = node[:web][:log_directory]
41
42 execute "cgimap-build" do
43   action :nothing
44   command "make"
45   cwd cgimap_directory
46   user "rails"
47   group "rails"
48 end
49
50 execute "cgimap-configure" do
51   action :nothing
52   command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib"
53   cwd cgimap_directory
54   user "rails"
55   group "rails"
56   notifies :run, "execute[cgimap-build]", :immediate
57 end
58
59 execute "cgimap-autogen" do
60   action :nothing
61   command "./autogen.sh"
62   cwd cgimap_directory
63   user "rails"
64   group "rails"
65   notifies :run, "execute[cgimap-configure]", :immediate
66 end
67
68 git cgimap_directory do
69   action :sync
70   repository "git://git.openstreetmap.org/cgimap.git"
71   revision "live"
72   user "rails"
73   group "rails"
74   notifies :run, "execute[cgimap-autogen]", :immediate
75 end
76
77 if node[:web][:readonly_database_host]
78   database_host = node[:web][:readonly_database_host]
79   database_readonly = true
80 else
81   database_host = node[:web][:database_host]
82   database_readonly = node[:web][:status] == "database_readonly"
83 end
84
85 cgimap_init = edit_file "#{cgimap_directory}/scripts/cgimap.init" do |line|
86   line.gsub!(/^CGIMAP_HOST=.*;/, "CGIMAP_HOST=#{database_host};")
87   line.gsub!(/^CGIMAP_DBNAME=.*;/, "CGIMAP_DBNAME=openstreetmap;")
88   line.gsub!(/^CGIMAP_USERNAME=.*;/, "CGIMAP_USERNAME=rails;")
89   line.gsub!(/^CGIMAP_PASSWORD=.*;/, "CGIMAP_PASSWORD=#{db_passwords['rails']};")
90   line.gsub!(/^CGIMAP_PIDFILE=.*;/, "CGIMAP_PIDFILE=#{pid_directory}/cgimap.pid;")
91   line.gsub!(/^CGIMAP_LOGFILE=.*;/, "CGIMAP_LOGFILE=#{log_directory}/cgimap.log;")
92   line.gsub!(/^CGIMAP_MEMCACHE=.*;/, "CGIMAP_MEMCACHE=rails1,rails2,rails3;")
93
94   line.gsub!(/\/home\/rails\/bin\/map/, "#{cgimap_directory}/map")
95
96   if database_readonly
97     line.gsub!(/--daemon/, "--daemon --readonly")
98   end
99
100   line
101 end
102
103 file "/etc/init.d/cgimap" do
104   owner "root"
105   group "root"
106   mode 0755
107   content cgimap_init
108 end
109
110 if ["database_offline", "api_offline"].include?(node[:web][:status])
111   service "cgimap" do
112     action :stop
113   end
114 else
115   service "cgimap" do
116     action [ :enable, :start ]
117     supports :restart => true, :reload => true
118     subscribes :restart, "execute[cgimap-build]"
119     subscribes :restart, "file[/etc/init.d/cgimap]"
120   end
121 end