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 # https://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"
22 include_recipe "memcached"
23 include_recipe "python"
26 package "libmysqlclient-dev"
29 python_directory = "/opt/osqa-python"
31 python_virtualenv python_directory
33 python_package "django" do
34 python_virtualenv python_directory
38 python_package "html5lib" do
39 python_virtualenv python_directory
43 python_package "markdown" do
44 python_virtualenv python_directory
48 python_package "python-memcached" do
49 python_virtualenv python_directory
53 python_package "python_openid" do
54 python_virtualenv python_directory
58 python_package "MySQL_python" do
59 python_virtualenv python_directory
63 python_package "psycopg2" do
64 python_virtualenv python_directory
68 python_package "South" do
69 python_virtualenv python_directory
73 apache_module "rewrite"
76 node[:osqa][:sites].each do |site|
77 site_name = site[:name]
78 site_aliases = site[:aliases] || []
79 directory = site[:directory] || "/srv/#{site_name}"
80 site_user = site[:user] || node[:osqa][:user]
81 site_user = Etc.getpwuid(site_user).name if site_user.is_a?(Integer)
82 site_group = site[:group] || node[:osqa][:group] || Etc.getpwnam(site_user).gid
83 site_group = Etc.getgrgid(site_group).name if site_group.is_a?(Integer)
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]
89 ssl_certificate site_name do
90 domains [site_name] + site_aliases
91 notifies :reload, "service[apache2]"
94 apache_site site_name do
97 variables :user => site_user, :group => site_group, :aliases => site_aliases
100 directory directory do
106 execute "osqa-migrate" do
108 command "python manage.py migrate forum"
109 cwd "#{directory}/osqa"
112 notifies :reload, "service[apache2]"
115 git "#{directory}/osqa" do
117 repository "https://git.openstreetmap.org/public/osqa.git"
121 notifies :run, "execute[osqa-migrate]"
124 directory "#{directory}/upfiles" do
130 template "#{directory}/osqa/osqa.wsgi" do
131 source "osqa.wsgi.erb"
135 variables :directory => directory
136 notifies :reload, "service[apache2]"
139 settings = edit_file "#{directory}/osqa/settings_local.py.dist" do |line|
140 line.gsub!(/^( *)'ENGINE': '.*',/, "\\1'ENGINE': 'django.db.backends.postgresql_psycopg2',")
141 line.gsub!(/^( *)'NAME': '.*',/, "\\1'NAME': '#{database_name}',")
142 line.gsub!(/^( *)'USER': '.*',/, "\\1'USER': '#{database_user}',")
143 line.gsub!(/^( *)'PASSWORD': '.*',/, "\\1'PASSWORD': '#{database_password}',")
144 line.gsub!(/^ALLOWED_HOSTS = .*/, "ALLOWED_HOSTS = ('help.openstreetmap.org',)")
145 line.gsub!(/^CACHE_BACKEND = .*/, "CACHE_BACKEND = 'memcached://127.0.0.1:11211/'")
146 line.gsub!(%r{^APP_URL = 'http://'}, "APP_URL = 'https://#{site_name}'")
147 line.gsub!(%r{^TIME_ZONE = 'America/New_York'}, "TIME_ZONE = 'Europe/London'")
148 line.gsub!(/^DISABLED_MODULES = \[([^\]]+)\]/, "DISABLED_MODULES = [\\1, 'localauth', 'facebookauth', 'oauthauth']")
153 file "#{directory}/osqa/settings_local.py" do
158 notifies :reload, "service[apache2]"
161 template "/etc/cron.daily/#{backup_name}-backup" do
162 source "backup.cron.erb"
166 variables :name => backup_name, :directory => directory, :user => site_user, :database => database_name