]> git.openstreetmap.org Git - chef.git/blob - cookbooks/osqa/recipes/default.rb
nominatim: install secondary importance file
[chef.git] / cookbooks / osqa / recipes / default.rb
1 #
2 # Cookbook:: osqa
3 # Recipe:: default
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 "accounts"
21 include_recipe "apache"
22 include_recipe "memcached"
23 include_recipe "postgresql"
24 include_recipe "python"
25 include_recipe "tools"
26
27 package "python-dev"
28 package "libmysqlclient-dev"
29 package "libpq-dev"
30
31 python_directory = "/opt/osqa-python"
32
33 python_virtualenv python_directory do
34   interpreter "/usr/bin/python2"
35 end
36
37 python_package "Django" do
38   python_virtualenv python_directory
39   version "1.6.11"
40 end
41
42 python_package "Markdown" do
43   python_virtualenv python_directory
44   version "2.4"
45 end
46
47 python_package "python-memcached" do
48   python_virtualenv python_directory
49   version "1.53"
50 end
51
52 python_package "python-openid" do
53   python_virtualenv python_directory
54   version "2.2.5"
55 end
56
57 python_package "psycopg2" do
58   python_virtualenv python_directory
59   version "2.7.6.1"
60 end
61
62 python_package "South" do
63   python_virtualenv python_directory
64   version "0.7.6"
65 end
66
67 python_package "html5lib" do
68   python_virtualenv python_directory
69   version "0.999"
70 end
71
72 apache_module "rewrite"
73 apache_module "wsgi"
74
75 node[:osqa][:sites].each do |site|
76   site_name = site[:name]
77   site_aliases = site[:aliases] || []
78   directory = site[:directory] || "/srv/#{site_name}"
79   site_user = site[:user] || node[:osqa][:user]
80   site_user = Etc.getpwuid(site_user).name if site_user.is_a?(Integer)
81   site_group = site[:group] || node[:osqa][:group] || Etc.getpwnam(site_user).gid
82   site_group = Etc.getgrgid(site_group).name if site_group.is_a?(Integer)
83   database_cluster = site[:database_cluster] || node[:osqa][:database_cluster]
84   database_name = site[:database_name] || node[:osqa][:database_name]
85   database_user = site[:database_user] || node[:osqa][:database_user]
86   database_password = site[:database_user] || node[:osqa][:database_password]
87   backup_name = site[:backup]
88
89   postgresql_user database_user do
90     cluster database_cluster
91     password database_password
92   end
93
94   postgresql_database database_name do
95     cluster database_cluster
96     owner database_user
97   end
98
99   ssl_certificate site_name do
100     domains [site_name] + site_aliases
101     notifies :reload, "service[apache2]"
102   end
103
104   apache_site site_name do
105     template "apache.erb"
106     directory directory
107     variables :user => site_user, :group => site_group, :aliases => site_aliases, :python_home => python_directory
108   end
109
110   directory directory do
111     owner site_user
112     group site_group
113     mode "755"
114   end
115
116   execute "osqa-migrate" do
117     action :nothing
118     command "python manage.py migrate forum"
119     cwd "#{directory}/osqa"
120     user site_user
121     group site_group
122     notifies :reload, "service[apache2]"
123   end
124
125   git "#{directory}/osqa" do
126     action :sync
127     repository "https://git.openstreetmap.org/public/osqa.git"
128     revision "live"
129     depth 1
130     user site_user
131     group site_group
132     notifies :run, "execute[osqa-migrate]"
133   end
134
135   directory "#{directory}/upfiles" do
136     user site_user
137     group site_group
138     mode "755"
139   end
140
141   template "#{directory}/osqa/osqa.wsgi" do
142     source "osqa.wsgi.erb"
143     owner site_user
144     group site_group
145     mode "644"
146     variables :directory => directory
147     notifies :reload, "service[apache2]"
148   end
149
150   settings = edit_file "#{directory}/osqa/settings_local.py.dist" do |line|
151     line.gsub!(/^( *)'ENGINE': '.*',/, "\\1'ENGINE': 'django.db.backends.postgresql_psycopg2',")
152     line.gsub!(/^( *)'NAME': '.*',/, "\\1'NAME': '#{database_name}',")
153     line.gsub!(/^( *)'USER': '.*',/, "\\1'USER': '#{database_user}',")
154     line.gsub!(/^( *)'PASSWORD': '.*',/, "\\1'PASSWORD': '#{database_password}',")
155     line.gsub!(/^ALLOWED_HOSTS = .*/, "ALLOWED_HOSTS = ('help.openstreetmap.org',)")
156     line.gsub!(/^CACHE_BACKEND = .*/, "CACHE_BACKEND = 'memcached://127.0.0.1:11211/'")
157     line.gsub!(%r{^APP_URL = 'http://'}, "APP_URL = 'https://#{site_name}'")
158     line.gsub!(%r{^TIME_ZONE = 'America/New_York'}, "TIME_ZONE = 'Europe/London'")
159     line.gsub!(/^DISABLED_MODULES = \[([^\]]+)\]/, "DISABLED_MODULES = [\\1, 'localauth', 'facebookauth', 'oauthauth', 'mysqlfulltext']")
160
161     line
162   end
163
164   file "#{directory}/osqa/settings_local.py" do
165     owner site_user
166     group site_group
167     mode "644"
168     content settings
169     notifies :reload, "service[apache2]"
170   end
171
172   template "/etc/cron.daily/#{backup_name}-backup" do
173     source "backup.cron.erb"
174     owner "root"
175     group "root"
176     mode "755"
177     variables :name => backup_name, :directory => directory, :user => site_user, :database => database_name
178   end
179 end