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