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 wp_config = edit_file "#{directory}/wp-config-sample.php" do |line|
68 line.gsub!(/database_name_here/, database_name)
69 line.gsub!(/username_here/, database_user)
70 line.gsub!(/password_here/, database_password)
71 line.gsub!(/wp_/, database_prefix)
73 line.gsub!(/('AUTH_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:auth_key]}'")
74 line.gsub!(/('SECURE_AUTH_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:secure_auth_key]}'")
75 line.gsub!(/('LOGGED_IN_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:logged_in_key]}'")
76 line.gsub!(/('NONCE_KEY', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:nonce_key]}'")
77 line.gsub!(/('AUTH_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:auth_salt]}'")
78 line.gsub!(/('SECURE_AUTH_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:secure_auth_salt]}'")
79 line.gsub!(/('LOGGED_IN_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:logged_in_salt]}'")
80 line.gsub!(/('NONCE_SALT', *)'put your unique phrase here'/, "\\1'#{node[:wordpress][:sites][name][:nonce_salt]}'")
82 if line =~ /define\('WP_DEBUG'/
85 line += " * Don't allow file editing.\n"
87 line += "define('DISALLOW_FILE_EDIT', true);\n"
93 file "#{directory}/wp-config.php" do
94 owner node[:wordpress][:user]
95 group node[:wordpress][:group]
98 notifies :reload, "service[apache2]"
101 directory "#{directory}/wp-content/uploads" do
107 file "#{directory}/sitemap.xml" do
113 file "#{directory}/sitemap.xml.gz" do
119 cookbook_file "#{directory}/googlefac54c35e800caab.html" do
121 owner node[:wordpress][:user]
122 group node[:wordpress][:group]
129 template "apache.erb"
131 variables :aliases => aliases, :urls => urls
132 notifies :reload, "service[apache2]"
135 http_request "http://#{name}/wp-admin/upgrade.php" do
137 url "http://#{name}/wp-admin/upgrade.php?step=1"
138 subscribes :get, "subversion[#{directory}]"
141 wordpress_plugin "wp-fail2ban" do
145 script "#{directory}/wp-content/plugins/wp-fail2ban" do
152 @include "wp-config.php";
153 @include_once "wp-includes/functions.php";
154 @include_once "wp-admin/includes/plugin.php";
155 activate_plugin("wp-fail2ban/wp-fail2ban.php", '', false, false);
158 subscribes :run, "subversion[#{directory}/wp-content/plugins/wp-fail2ban]"