2 # Cookbook Name:: drupal
3 # Definition:: drupal_site
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 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
34 if site_action.include?(:create)
35 directory "/data/#{site_name}" do
42 directory "/data/#{site_name}/files" do
48 directory "/data/#{site_name}/private" do
54 directory "/etc/drupal/7/sites/#{site_name}" do
60 link "/etc/drupal/7/sites/#{site_name}/files" do
61 to "/data/#{site_name}/files"
64 link "/etc/drupal/7/sites/#{site_name}/private" do
65 to "/data/#{site_name}/private"
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"
73 creates "/etc/drupal/7/sites/#{site_name}/settings.php"
76 apache_site site_name do
78 template ssl ? "apache-ssl.erb" : "apache.erb"
80 elsif site_action.include?(:delete)