5 # Copyright 2011, OpenStreetMap Foundation
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 include_recipe "tools"
21 include_recipe "apache::ssl"
22 include_recipe "memcached"
24 package "python-django"
25 package "python-html5lib"
26 package "python-markdown"
27 package "python-memcache"
28 package "python-openid"
29 package "python-mysqldb"
30 package "python-psycopg2"
31 package "python-setuptools"
33 easy_install_package "South" do
37 apache_module "rewrite"
40 node[:osqa][:sites].each do |site|
41 site_name = site[:name]
42 directory = site[:directory] || "/srv/#{site_name}"
43 site_user = site[:user] || node[:osqa][:user]
44 site_user = Etc.getpwuid(site_user).name if site_user.is_a?(Integer)
45 site_group = site[:group] || node[:osqa][:group] || Etc.getpwnam(site_user).gid
46 site_group = Etc.getgrgid(site_group).name if site_group.is_a?(Integer)
47 database_name = site[:database_name] || node[:osqa][:database_name]
48 database_user = site[:database_user] || node[:osqa][:database_user]
49 database_password = site[:database_user] || node[:osqa][:database_password]
50 backup_name = site[:backup]
52 ssl_certificate site_name do
54 fallback_certificate "openstreetmap"
55 notifies :reload, "service[apache2]"
58 apache_site site_name do
61 variables :user => site_user, :group => site_group
64 directory directory do
70 execute "osqa-migrate" do
72 command "python manage.py migrate forum"
73 cwd "#{directory}/osqa"
76 notifies :reload, "service[apache2]"
79 git "#{directory}/osqa" do
81 repository "git://git.openstreetmap.org/osqa.git"
85 notifies :run, "execute[osqa-migrate]"
88 directory "#{directory}/upfiles" do
94 template "#{directory}/osqa/osqa.wsgi" do
95 source "osqa.wsgi.erb"
99 variables :directory => directory
100 notifies :reload, "service[apache2]"
103 settings = edit_file "#{directory}/osqa/settings_local.py.dist" do |line|
104 line.gsub!(/^( *)'ENGINE': '.*',/, "\\1'ENGINE': 'django.db.backends.postgresql_psycopg2',")
105 line.gsub!(/^( *)'NAME': '.*',/, "\\1'NAME': '#{database_name}',")
106 line.gsub!(/^( *)'USER': '.*',/, "\\1'USER': '#{database_user}',")
107 line.gsub!(/^( *)'PASSWORD': '.*',/, "\\1'PASSWORD': '#{database_password}',")
108 line.gsub!(/^ALLOWED_HOSTS = .*/, "ALLOWED_HOSTS = ('help.openstreetmap.org',)")
109 line.gsub!(/^CACHE_BACKEND = .*/, "CACHE_BACKEND = 'memcached://127.0.0.1:11211/'")
110 line.gsub!(%r{^APP_URL = 'http://'}, "APP_URL = 'https://#{site_name}'")
111 line.gsub!(%r{^TIME_ZONE = 'America/New_York'}, "TIME_ZONE = 'Europe/London'")
112 line.gsub!(/^DISABLED_MODULES = \[([^\]]+)\]/, "DISABLED_MODULES = [\\1, 'localauth', 'facebookauth', 'oauthauth']")
117 file "#{directory}/osqa/settings_local.py" do
122 notifies :reload, "service[apache2]"
125 template "/etc/cron.daily/#{backup_name}-backup" do
126 source "backup.cron.erb"
130 variables :name => backup_name, :directory => directory, :user => site_user, :database => database_name