2 # Cookbook Name:: wordpress
3 # Definition:: wordpress_site
5 # Copyright 2013, 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 :wordpress_site, :action => [ :create, :enable ] do
22 aliases = Array(params[:aliases])
23 urls = Array(params[:urls])
24 directory = params[:directory] || "/srv/#{name}"
25 version = params[:version] || Chef::Wordpress.current_version
26 database_name = params[:database_name]
27 database_user = params[:database_user]
28 database_password = params[:database_password]
29 database_prefix = params[:database_prefix] || "wp_"
31 node.set_unless[:wordpress][:sites][name] = {}
33 node.set[:wordpress][:sites][name][:directory] = directory
35 node.set_unless[:wordpress][:sites][name][:auth_key] = random_password(64)
36 node.set_unless[:wordpress][:sites][name][:secure_auth_key] = random_password(64)
37 node.set_unless[:wordpress][:sites][name][:logged_in_key] = random_password(64)
38 node.set_unless[:wordpress][:sites][name][:nonce_key] = random_password(64)
39 node.set_unless[:wordpress][:sites][name][:auth_salt] = random_password(64)
40 node.set_unless[:wordpress][:sites][name][:secure_auth_salt] = random_password(64)
41 node.set_unless[:wordpress][:sites][name][:logged_in_salt] = random_password(64)
42 node.set_unless[:wordpress][:sites][name][:nonce_salt] = random_password(64)
44 mysql_user "#{database_user}@localhost" do
45 password database_password
48 mysql_database database_name do
49 permissions "#{database_user}@localhost" => :all
52 directory directory do
53 owner node[:wordpress][:user]
54 group node[:wordpress][:group]
58 subversion directory do
60 repository "http://core.svn.wordpress.org/tags/#{version}"
61 user node[:wordpress][:user]
62 group node[:wordpress][:group]
64 notifies :reload, "service[apache2]"
67 file "#{directory}/wp-config.php" do
68 owner node[:wordpress][:user]
69 group node[:wordpress][:group]
71 content_from_file "#{directory}/wp-config-sample.php" do |line|
72 line.gsub!(/database_name_here/, database_name)
73 line.gsub!(/username_here/, database_user)
74 line.gsub!(/password_here/, database_password)
75 line.gsub!(/wp_/, database_prefix)
77 line.gsub!(/('AUTH_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:auth_key]}'")
78 line.gsub!(/('SECURE_AUTH_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:secure_auth_key]}'")
79 line.gsub!(/('LOGGED_IN_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:logged_in_key]}'")
80 line.gsub!(/('NONCE_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:nonce_key]}'")
81 line.gsub!(/('AUTH_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:auth_salt]}'")
82 line.gsub!(/('SECURE_AUTH_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:secure_auth_salt]}'")
83 line.gsub!(/('LOGGED_IN_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:logged_in_salt]}'")
84 line.gsub!(/('NONCE_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:nonce_salt]}'")
86 if line =~ /define\('WP_DEBUG'/
89 line += " * Don't allow file editing.\n"
91 line += "define('DISALLOW_FILE_EDIT', true);\n"
96 notifies :reload, "service[apache2]"
99 directory "#{directory}/wp-content/uploads" do
105 file "#{directory}/sitemap.xml" do
111 file "#{directory}/sitemap.xml.gz" do
117 cookbook_file "#{directory}/googlefac54c35e800caab.html" do
119 owner node[:wordpress][:user]
120 group node[:wordpress][:group]
127 template "apache.erb"
129 variables :aliases => aliases, :urls => urls
130 notifies :reload, "service[apache2]"
133 http_request "http://#{name}/wp-admin/upgrade.php" do
135 url "http://#{name}/wp-admin/upgrade.php?step=1"
136 subscribes :get, "subversion[#{directory}]"