forked from nephoscale/cloudscript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwordpress.cloudscript
More file actions
197 lines (156 loc) · 7.27 KB
/
wordpress.cloudscript
File metadata and controls
197 lines (156 loc) · 7.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# Install latest WordPress on a CS1-SSD Cloudlet ($.015/hr) running Linux Ubuntu Server 14.04 LTS 64-bit
cloudscript wordpress_single_stack
version = _latest
result_template = wordpress_result_template
globals
wp_image_type = 'Ubuntu Server 14.04 LTS'
wp_instance_type = 'CS1-SSD' # 1GB RAM, 1 vCore, 25GB SSD, 10Gbps
wp_hostname = 'wordpress'
server_password = lib::random_password()
console_password = lib::random_password()
mysql_root_password = lib::random_password()
wordpress_admin_password = lib::random_password()
wordpress_slice_user = 'wordpress'
wordpress_db_username = 'wordpress'
wordpress_db_name = 'wordpress'
wordpress_db_password = lib::random_password()
wordpress_auth_key = lib::random_password()
wordpress_secure_auth_key = lib::random_password()
wordpress_logged_in_key = lib::random_password()
wordpress_nonce_key = lib::random_password()
wordpress_auth_salt = lib::random_password()
wordpress_secure_auth_salt = lib::random_password()
wordpress_logged_in_salt = lib::random_password()
wordpress_nonce_salt = lib::random_password()
thread wordpress_setup
tasks = [wordpress_server_setup]
task wordpress_server_setup
#-----------------------
# create wordpress keys
#-----------------------
# create wordpress server root password key
/key/password wordpress_server_password_key read_or_create
key_group = _SERVER
password = server_password
# create wordpress server console key
/key/password wordpress_server_console_key read_or_create
key_group = _CONSOLE
password = console_password
# create storage slice keys
/key/token wordpress_slice_key read_or_create
username = wordpress_slice_user
#----------------------------
# create wordpress bootstrap
# script and recipe
#----------------------------
# create slice to store script in cloudstorage
/storage/slice wordpress_slice read_or_create
keys = [wordpress_slice_key]
# create slice container to store script in cloudstorage
/storage/container wordpress_container => [wordpress_slice] read_or_create
slice = wordpress_slice
# place script data in cloudstorage
/storage/object wordpress_bootstrap_object => [wordpress_slice, wordpress_container] read_or_create
container_name = 'wordpress_container'
file_name = 'bootstrap_wordpress.sh'
slice = wordpress_slice
content_data = wordpress_bootstrap_data
# associate the cloudstorage object with the wordpress script
/orchestration/script wordpress_bootstrap_script => [wordpress_slice, wordpress_container, wordpress_bootstrap_object] read_or_create
data_uri = 'cloudstorage://wordpress_slice/wordpress_container/bootstrap_wordpress.sh'
script_type = _SHELL
encoding = _STORAGE
# create the recipe and associate the script
/orchestration/recipe wordpress_bootstrap_recipe read_or_create
scripts = [wordpress_bootstrap_script]
#-------------------------
# create wordpress server
#-------------------------
# create a new instance of wordpress every time the cloudscript is run
/server/cloud wordpress_server create_enumerate
hostname = '{{ wp_hostname }}'
image = '{{ wp_image_type }}'
service_type = '{{ wp_instance_type }}'
keys = [wordpress_server_password_key, wordpress_server_console_key]
recipes = [wordpress_bootstrap_recipe]
text_template wordpress_bootstrap_data
#!/bin/sh
#-------------------------
# Install packages
#-------------------------
# get latest package list
apt-get update
# install apache2
apt-get install -y apache2
# let the user know wordpress is coming
echo "Wordpress is installing, please wait..." > /var/www/index.html
# prepare mysql preseed
MYSQL_ROOT_PWD={{ mysql_root_password }}
echo "mysql-server-5.1 mysql-server/root_password password $MYSQL_ROOT_PWD" > mysql.preseed
echo "mysql-server-5.1 mysql-server/root_password_again password $MYSQL_ROOT_PWD" >> mysql.preseed
echo "mysql-server-5.1 mysql-server/start_on_boot boolean true" >> mysql.preseed
cat mysql.preseed | sudo debconf-set-selections
rm mysql.preseed
# install php/mysql packages
apt-get -y install mysql-server
apt-get -y install libapache2-mod-php5
apt-get -y install php5-mysql
# Change apache config & restart apache to use the modules
sed -r 's@DocumentRoot /var/www/html@DocumentRoot /var/www@g'/etc/apache2/sites-available/000-default.conf > /etc/apache2/sites-available/111-default.conf
mv /etc/apache2/sites-available/111-default.conf /etc/apache2/sites-available/000-default.conf
service apache2 restart
# download wordpress
wget -O /tmp/latest.tgz http://wordpress.org/latest.tar.gz
# extract it and fix permissions
cd /var/www
tar xvfz /tmp/latest.tgz > /dev/null
chown -R www-data:www-data /var/www
#-------------------------
# Set MySQL Permissions
#-------------------------
cat <<\EOF>/tmp/setup.mysql
CREATE DATABASE if not exists {{ wordpress_db_name }};
CREATE USER {{ wordpress_db_username }}@'localhost' identified by '{{ wordpress_db_password }}';
GRANT ALL ON wordpress.* to {{ wordpress_db_username }}@'localhost';
FLUSH PRIVILEGES;
EOF
mysql -u root --password='{{ mysql_root_password }}' < /tmp/setup.mysql
rm /tmp/setup.mysql
#-----------------------------
# Create wordpress config file
#-----------------------------
cat <<\EOF>/var/www/wordpress/wp-config.php
<?php
define('DB_NAME', '{{ wordpress_db_name }}');
define('DB_USER', '{{ wordpress_db_username }}');
define('DB_PASSWORD', '{{ wordpress_db_password }}');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');
define('AUTH_KEY', '{{ wordpress_auth_key }}');
define('SECURE_AUTH_KEY', '{{ wordpress_secure_auth_key }}');
define('LOGGED_IN_KEY', '{{ wordpress_logged_in_key }}');
define('NONCE_KEY', '{{ wordpress_nonce_key }}');
define('AUTH_SALT', '{{ wordpress_auth_salt }}');
define('SECURE_AUTH_SALT', '{{ wordpress_secure_auth_salt }}');
define('LOGGED_IN_SALT', '{{ wordpress_logged_in_salt }}');
define('NONCE_SALT', '{{ wordpress_nonce_salt }}');
$table_prefix = 'wp_';
define('WPLANG', '');
define('WP_DEBUG', false);
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');
EOF
# move temporary wordpress install into '/'
mv /var/www/wordpress/* /var/www
rmdir /var/www/wordpress
# remove temporary index.html giving way to index.php
rm -rf /var/www/index.html
_eof
text_template wordpress_result_template
Your wordpress site is ready at the following URL:
http://{{ wordpress_server.ipaddress_public }}/
_eof