]> git.openstreetmap.org Git - chef.git/blob - cookbooks/osqa/recipes/default.rb
Imagery: set GDAL_CACHEMAX environment variable
[chef.git] / cookbooks / osqa / recipes / default.rb
1 #
2 # Cookbook Name:: 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 "tools"
21 include_recipe "apache"
22 include_recipe "memcached"
23 include_recipe "python"
24
25 package "python-django"
26 package "python-html5lib"
27 package "python-markdown"
28 package "python-memcache"
29 package "python-openid"
30 package "python-mysqldb"
31 package "python-psycopg2"
32 package "python-setuptools"
33
34 python_package "South"
35
36 apache_module "rewrite"
37 apache_module "wsgi"
38
39 node[:osqa][:sites].each do |site|
40   site_name = site[:name]
41   directory = site[:directory] || "/srv/#{site_name}"
42   site_user = site[:user] || node[:osqa][:user]
43   site_user = Etc.getpwuid(site_user).name if site_user.is_a?(Integer)
44   site_group = site[:group] || node[:osqa][:group] || Etc.getpwnam(site_user).gid
45   site_group = Etc.getgrgid(site_group).name if site_group.is_a?(Integer)
46   database_name = site[:database_name] || node[:osqa][:database_name]
47   database_user = site[:database_user] || node[:osqa][:database_user]
48   database_password = site[:database_user] || node[:osqa][:database_password]
49   backup_name = site[:backup]
50
51   ssl_certificate site_name do
52     domains site_name
53     notifies :reload, "service[apache2]"
54   end
55
56   apache_site site_name do
57     template "apache.erb"
58     directory directory
59     variables :user => site_user, :group => site_group
60   end
61
62   directory directory do
63     owner site_user
64     group site_group
65     mode 0o755
66   end
67
68   execute "osqa-migrate" do
69     action :nothing
70     command "python manage.py migrate forum"
71     cwd "#{directory}/osqa"
72     user site_user
73     group site_group
74     notifies :reload, "service[apache2]"
75   end
76
77   git "#{directory}/osqa" do
78     action :sync
79     repository "https://git.openstreetmap.org/public/osqa.git"
80     revision "live"
81     user site_user
82     group site_group
83     notifies :run, "execute[osqa-migrate]"
84   end
85
86   directory "#{directory}/upfiles" do
87     user site_user
88     group site_group
89     mode 0o755
90   end
91
92   template "#{directory}/osqa/osqa.wsgi" do
93     source "osqa.wsgi.erb"
94     owner site_user
95     group site_group
96     mode 0o644
97     variables :directory => directory
98     notifies :reload, "service[apache2]"
99   end
100
101   settings = edit_file "#{directory}/osqa/settings_local.py.dist" do |line|
102     line.gsub!(/^( *)'ENGINE': '.*',/, "\\1'ENGINE': 'django.db.backends.postgresql_psycopg2',")
103     line.gsub!(/^( *)'NAME': '.*',/, "\\1'NAME': '#{database_name}',")
104     line.gsub!(/^( *)'USER': '.*',/, "\\1'USER': '#{database_user}',")
105     line.gsub!(/^( *)'PASSWORD': '.*',/, "\\1'PASSWORD': '#{database_password}',")
106     line.gsub!(/^ALLOWED_HOSTS = .*/, "ALLOWED_HOSTS = ('help.openstreetmap.org',)")
107     line.gsub!(/^CACHE_BACKEND = .*/, "CACHE_BACKEND = 'memcached://127.0.0.1:11211/'")
108     line.gsub!(%r{^APP_URL = 'http://'}, "APP_URL = 'https://#{site_name}'")
109     line.gsub!(%r{^TIME_ZONE = 'America/New_York'}, "TIME_ZONE = 'Europe/London'")
110     line.gsub!(/^DISABLED_MODULES = \[([^\]]+)\]/, "DISABLED_MODULES = [\\1, 'localauth', 'facebookauth', 'oauthauth']")
111
112     line
113   end
114
115   file "#{directory}/osqa/settings_local.py" do
116     owner site_user
117     group site_group
118     mode 0o644
119     content settings
120     notifies :reload, "service[apache2]"
121   end
122
123   template "/etc/cron.daily/#{backup_name}-backup" do
124     source "backup.cron.erb"
125     owner "root"
126     group "root"
127     mode 0o755
128     variables :name => backup_name, :directory => directory, :user => site_user, :database => database_name
129   end
130 end