]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/recipes/cgimap.rb
73114c1e746e5b5f8020f8ac4bc2d23ed8f469fc
[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 "zlib1g-dev"
36
37 if node[:lsb][:release].to_f < 12.04
38   package "libpqxx-dev"
39 else
40   package "libpqxx3-dev"
41 end
42
43 cgimap_directory = "#{node[:web][:base_directory]}/cgimap"
44 pid_directory = node[:web][:pid_directory]
45 log_directory = node[:web][:log_directory]
46
47 execute "cgimap-build" do
48   action :nothing
49   command "make"
50   cwd cgimap_directory
51   user "rails"
52   group "rails"
53 end
54
55 execute "cgimap-configure" do
56   action :nothing
57   command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib"
58   cwd cgimap_directory
59   user "rails"
60   group "rails"
61   notifies :run, resources(:execute => "cgimap-build"), :immediate
62 end
63
64 execute "cgimap-autogen" do
65   action :nothing
66   command "./autogen.sh"
67   cwd cgimap_directory
68   user "rails"
69   group "rails"
70   notifies :run, resources(:execute => "cgimap-configure"), :immediate
71 end
72
73 git cgimap_directory do
74   action :sync
75   repository "git://git.openstreetmap.org/cgimap.git"
76   revision "live"
77   user "rails"
78   group "rails"
79   notifies :run, resources(:execute => "cgimap-autogen"), :immediate
80 end
81
82 if node[:web][:readonly_database_host]
83   database_host = node[:web][:readonly_database_host]
84   database_readonly = true
85 else
86   database_host = node[:web][:database_host]
87   database_readonly = node[:web][:status] == "database_readonly"
88 end
89
90 file "/etc/init.d/cgimap" do
91   owner "root"
92   group "root"
93   mode 0755
94   content_from_file "#{cgimap_directory}/scripts/cgimap.init" do |line|
95     line.gsub!(/^CGIMAP_HOST=.*;/, "CGIMAP_HOST=#{database_host};")
96     line.gsub!(/^CGIMAP_DBNAME=.*;/, "CGIMAP_DBNAME=openstreetmap;")
97     line.gsub!(/^CGIMAP_USERNAME=.*;/, "CGIMAP_USERNAME=rails;")
98     line.gsub!(/^CGIMAP_PASSWORD=.*;/, "CGIMAP_PASSWORD=#{db_passwords['rails']};")
99     line.gsub!(/^CGIMAP_PIDFILE=.*;/, "CGIMAP_PIDFILE=#{pid_directory}/cgimap.pid;")
100     line.gsub!(/^CGIMAP_LOGFILE=.*;/, "CGIMAP_LOGFILE=#{log_directory}/cgimap.log;")
101     line.gsub!(/^CGIMAP_MEMCACHE=.*;/, "CGIMAP_MEMCACHE=rails1,rails2,rails3;")
102
103     line.gsub!(/\/home\/rails\/bin\/map/, "#{cgimap_directory}/map")
104
105     if database_readonly
106       line.gsub!(/--daemon/, "--daemon --readonly")
107     end
108
109     line
110   end
111 end
112
113 if ["database_offline", "api_offline"].include?(node[:web][:status])
114   service "cgimap" do
115     action :stop
116   end
117 else
118   service "cgimap" do
119     action [ :enable, :start ]
120     supports :restart => true, :reload => true
121     subscribes :restart, resources(:execute => "cgimap-build")
122     subscribes :restart, resources(:file => "/etc/init.d/cgimap")
123   end
124 end