]> git.openstreetmap.org Git - chef.git/blob - cookbooks/drupal/definitions/drupal_site.rb
supybot: Add owl to watched repos
[chef.git] / cookbooks / drupal / definitions / drupal_site.rb
1 #
2 # Cookbook Name:: drupal
3 # Definition:: drupal_site
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 define :drupal_site, :action => [ :create ], :variables => {} do
21   site_name = params[:name]
22   site_action = params[:action]
23   site_title = params[:title] || site_name
24   short_name = site_name.sub(/\..*$/, "")
25   db_name = params[:database_name] || short_name
26   db_username = params[:database_username] || short_name
27   db_password = params[:database_password]
28   db_url = "mysql://#{db_username}:#{db_password}@localhost/#{db_name}"
29   admin_username = params[:admin_username] || "admin"
30   admin_password = params[:admin_password]
31   admin_email = params[:admin_email] || "webmaster@openstreetmap.org"
32   ssl = params[:ssl] || false
33
34   if site_action.include?(:create)
35     directory "/data/#{site_name}" do
36       owner "www-data"
37       group "www-data"
38       mode "0775"
39       recursive true
40     end
41
42     directory "/data/#{site_name}/files" do
43       owner "www-data"
44       group "www-data"
45       mode "0775"
46     end
47
48     directory "/data/#{site_name}/private" do
49       owner "www-data"
50       group "www-data"
51       mode "0775"
52     end
53
54     directory "/etc/drupal/7/sites/#{site_name}" do
55       owner "root"
56       group "root"
57       mode "0555"
58     end
59
60     link "/etc/drupal/7/sites/#{site_name}/files" do
61       to "/data/#{site_name}/files"
62     end
63
64     link "/etc/drupal/7/sites/#{site_name}/private" do
65       to "/data/#{site_name}/private"
66     end
67
68     execute "drupal-site-install-#{short_name}" do
69       command "drush site-install --account-name=#{admin_username} --account-pass=#{admin_password} --account-mail=#{admin_email} --db-url=#{db_url} --site-name=#{site_title} --site-mail=webmaster@openstreetmap.org --sites-subdir=#{site_name} --yes"
70       cwd "/usr/share/drupal7"
71       user "root"
72       group "root"
73       creates "/etc/drupal/7/sites/#{site_name}/settings.php"
74     end
75
76     apache_site site_name do
77       cookbook "drupal"
78       template ssl ? "apache-ssl.erb" : "apache.erb"
79     end
80   elsif site_action.include?(:delete)
81   end
82 end