]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/recipes/cgimap.rb
067b9e3f5dad525c43101e38428b2698632dab19
[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 "g++"
26 package "gcc"
27 package "make"
28 package "autoconf"
29 package "automake"
30 package "libtool"
31 package "libfcgi-dev"
32 package "libxml2-dev"
33 package "libmemcached-dev"
34 package "libboost-regex-dev"
35 package "libboost-system-dev"
36 package "libboost-program-options-dev"
37 package "libboost-date-time-dev"
38 package "libboost-filesystem-dev"
39 package "libpqxx-dev"
40 package "zlib1g-dev"
41
42 cgimap_directory = "#{node[:web][:base_directory]}/cgimap"
43 pid_directory = node[:web][:pid_directory]
44 log_directory = node[:web][:log_directory]
45
46 execute "cgimap-build" do
47   action :nothing
48   command "make"
49   cwd cgimap_directory
50   user "rails"
51   group "rails"
52 end
53
54 execute "cgimap-configure" do
55   action :nothing
56   command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu"
57   cwd cgimap_directory
58   user "rails"
59   group "rails"
60   notifies :run, "execute[cgimap-build]", :immediate
61 end
62
63 execute "cgimap-autogen" do
64   action :nothing
65   command "./autogen.sh"
66   cwd cgimap_directory
67   user "rails"
68   group "rails"
69   notifies :run, "execute[cgimap-configure]", :immediate
70 end
71
72 git cgimap_directory do
73   action :sync
74   repository "git://git.openstreetmap.org/cgimap.git"
75   revision "live"
76   user "rails"
77   group "rails"
78   notifies :run, "execute[cgimap-autogen]", :immediate
79 end
80
81 if node[:web][:readonly_database_host]
82   database_host = node[:web][:readonly_database_host]
83   database_readonly = true
84 else
85   database_host = node[:web][:database_host]
86   database_readonly = node[:web][:status] == "database_readonly"
87 end
88
89 memcached_servers = node[:web][:memcached_servers]
90
91 cgimap_init = edit_file "#{cgimap_directory}/scripts/cgimap.init" do |line|
92   line.gsub!(/^CGIMAP_HOST=.*;/, "CGIMAP_HOST=#{database_host};")
93   line.gsub!(/^CGIMAP_DBNAME=.*;/, "CGIMAP_DBNAME=openstreetmap;")
94   line.gsub!(/^CGIMAP_USERNAME=.*;/, "CGIMAP_USERNAME=rails;")
95   line.gsub!(/^CGIMAP_PASSWORD=.*;/, "CGIMAP_PASSWORD=#{db_passwords['rails']};")
96   line.gsub!(/^CGIMAP_PIDFILE=.*;/, "CGIMAP_PIDFILE=#{pid_directory}/cgimap.pid;")
97   line.gsub!(/^CGIMAP_LOGFILE=.*;/, "CGIMAP_LOGFILE=#{log_directory}/cgimap.log;")
98   line.gsub!(/^CGIMAP_MEMCACHE=.*;/, "CGIMAP_MEMCACHE=#{memcached_servers.join(',')};")
99   line.gsub!(/^CGIMAP_RATELIMIT=.*;/, "CGIMAP_RATELIMIT=204800;")
100
101   line.gsub!(%r{--pidfile \$CGIMAP_PIDFILE --exec /home/rails/bin/openstreetmap-cgimap}, "--pidfile $CGIMAP_PIDFILE")
102
103   line.gsub!(%r{/home/rails/bin/openstreetmap-cgimap}, "#{cgimap_directory}/openstreetmap-cgimap")
104
105   if database_readonly
106     line.gsub!(/--daemon/, "--daemon --readonly")
107   end
108
109   line
110 end
111
112 file "/etc/init.d/cgimap" do
113   owner "root"
114   group "root"
115   mode 0755
116   content cgimap_init
117 end
118
119 if %w(database_offline api_offline).include?(node[:web][:status])
120   service "cgimap" do
121     action :stop
122   end
123 else
124   service "cgimap" do
125     action [:enable, :start]
126     supports :restart => true, :reload => true
127     subscribes :restart, "execute[cgimap-build]"
128     subscribes :restart, "file[/etc/init.d/cgimap]"
129   end
130 end