]> git.openstreetmap.org Git - chef.git/blob - cookbooks/osqa/recipes/default.rb
Add a load more cookbooks
[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 #     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 "apache::ssl"
22 include_recipe "memcached"
23
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"
32
33 easy_install_package "South" do
34   package_name "south"
35 end
36
37 apache_module "rewrite"
38 apache_module "wsgi"
39
40 node[:osqa][:sites].each do |site|
41   name = site[:name]
42   directory = site[:directory] || "/var/www/#{name}"
43   osqa_revision = site[:revision] || node[:osqa][:revision]
44   site_user = site[:user] || node[:osqa][:user]
45   site_user = Etc.getpwuid(site_user).name if site_user.is_a?(Integer)
46   site_group = site[:group] || node[:osqa][:group] || Etc.getpwnam(site_user).gid
47   site_group = Etc.getgrgid(site_group).name if site_group.is_a?(Integer)
48   database_name = site[:database_name] || node[:osqa][:database_name]
49   database_user = site[:database_user] || node[:osqa][:database_user]
50   database_password = site[:database_user] || node[:osqa][:database_password]
51
52   apache_site name do
53     template "apache.erb"
54     directory "#{directory}/osqa"
55     variables :user => site_user, :group => site_group
56   end
57
58   execute "osqa-migrate" do
59     action :nothing
60     command "python manage.py migrate forum"
61     cwd "#{directory}/osqa"
62     user site_user
63     group site_group
64     notifies :reload, resources(:service => "apache2")
65   end
66
67   subversion "#{directory}/osqa" do
68     action :sync
69     repository "http://svn.osqa.net/svnroot/osqa/trunk"
70     revision osqa_revision
71     user site_user
72     group site_group
73     notifies :run, resources(:execute => "osqa-migrate")
74   end
75
76   remote_directory "#{directory}/osqa/forum_modules/osmauth" do
77     source "osmauth"
78     owner site_user
79     group site_group
80     mode 0755
81     files_owner site_user
82     files_group site_group
83     files_mode 0644
84   end
85
86   template "#{directory}/osqa/osqa.wsgi" do
87     source "osqa.wsgi.erb"
88     owner site_user
89     group site_group
90     mode 0644
91     variables :directory => directory
92     notifies :reload, resources(:service => "apache2")
93   end
94
95   file "#{directory}/osqa/settings_local.py" do
96     owner site_user
97     group site_group
98     mode 0644
99     content_from_file "#{directory}/osqa/settings_local.py.dist" do |line|
100       line.gsub!(/^( *)'ENGINE': '.*',/, "\\1'ENGINE': 'django.db.backends.postgresql_psycopg2',")
101       line.gsub!(/^( *)'NAME': '.*',/, "\\1'NAME': '#{database_name}',")
102       line.gsub!(/^( *)'USER': '.*',/, "\\1'USER': '#{database_user}',")
103       line.gsub!(/^( *)'PASSWORD': '.*',/, "\\1'PASSWORD': '#{database_password}',")
104       line.gsub!(/^CACHE_BACKEND = .*/, "CACHE_BACKEND = 'memcached://127.0.0.1:11211/'")
105       line.gsub!(/^APP_URL = 'http:\/\/'/, "APP_URL = 'http://#{name}'")
106       line.gsub!(/^TIME_ZONE = 'America\/New_York'/, "TIME_ZONE = 'Europe/London'")
107       line.gsub!(/^DISABLED_MODULES = \[([^\]]+)\]/, "DISABLED_MODULES = [\\1, 'localauth', 'facebookauth', 'oauthauth']")
108
109       line
110     end
111     notifies :reload, resources(:service => "apache2")
112   end
113 end