forked from nephoscale/cloudscript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdrupal.cloudscript
More file actions
214 lines (173 loc) · 6.32 KB
/
drupal.cloudscript
File metadata and controls
214 lines (173 loc) · 6.32 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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Install Drupal 7.34 on a CS1-SSD Cloudlet ($.015/hr) running Linux Ubuntu Server 14.04 LTS 64-bit
cloudscript drupal_single_stack
version = '2014_12_24'
result_template = drupal_result_template
globals
drupal_hostname = 'drupal'
drupal_instance_type = 'CS1-SSD' # 1GB RAM, 1 vCore, 25GB SSD, 10Gbps
drupal_image_type = 'Ubuntu Server 14.04 LTS'
drupal_version = 'drupal-7.34'
server_password = lib::random_password()
console_password = lib::random_password()
drupal_db_password = lib::random_password()
drupal_db_name = 'drupal'
drupal_db_username = 'drupal'
drupal_slice_user = 'drupal'
thread drupal_install
tasks = [config]
task config
#--------------------
# create drupal keys
#--------------------
/key/password drupal_server_key read_or_create
key_group = _SERVER
password = server_password
/key/password drupal_console_key read_or_create
key_group = _CONSOLE
password = console_password
#------------------------------
# create drupal storage slice,
# bootstrap script and recipe
#------------------------------
# storage slice key
/key/token drupal_slice_key read_or_create
username = drupal_slice_user
# slice
/storage/slice drupal_slice read_or_create
keys = [drupal_slice_key]
# slice container
/storage/container drupal_container => [drupal_slice] read_or_create
slice = drupal_slice
# store script as object in cloudstorage
/storage/object drupal_install_script_object => [drupal_slice, drupal_container] read_or_create
container_name = 'drupal_container'
file_name = 'install_drupal.sh'
slice = drupal_slice
content_data = install_drupal_sh
# associate the cloudstorage object with the drupal script
/orchestration/script drupal_install_script => [drupal_slice, drupal_container, drupal_install_script_object] read_or_create
data_uri = 'cloudstorage://drupal_slice/drupal_container/install_drupal.sh'
script_type = _SHELL
encoding = _STORAGE
# create the recipe and associate the script
/orchestration/recipe drupal_install_recipe read_or_create
scripts = [drupal_install_script]
#--------------------
# create drupal node
#--------------------
# create a new instance of drupal every time the cloudscript is run
/server/cloud drupal_server create_enumerate
hostname = '{{ drupal_hostname }}'
image = '{{ drupal_image_type }}'
service_type = '{{ drupal_instance_type }}'
keys = [drupal_server_key, drupal_console_key]
recipes = [drupal_install_recipe]
text_template install_drupal_sh
#!/bin/bash
#
# install drupal service
#
# check permissions
[ `whoami` = 'root' ] || {
echo "ERROR: must have root permissions to execute the commands"
exit 1
}
apt-get update > /dev/null
[ $? -eq 0 ] && echo "OK: update local apt cache" || {
echo "ERROR: update local apt cache"
exit 1
}
# install MySQL
DEBIAN_FRONTEND=noninteractive apt-get install -y mysql-server mysql-client > /dev/null
[ $? -eq 0 ] && echo "OK: install MySQL" || {
echo "ERROR: install MySQL"
exit 1
}
# install Apache2
DEBIAN_FRONTEND=noninteractive apt-get install -y apache2 > /dev/null
[ $? -eq 0 ] && echo "OK: install Apache2" || {
echo "ERROR: install Apache2"
exit 1
}
# install PHP5
apt-get install -y php5 php5-cli libapache2-mod-php5 > /dev/null
[ $? -eq 0 ] && echo "OK: install PHP5" || {
echo "ERROR: install PHP5"
exit 1
}
# install required PHP5 modules
apt-get install -y php5-mysql php5-gd php5-curl > /dev/null
[ $? -eq 0 ] && echo "OK: install PHP5 modules" || {
echo "ERROR: install PHP5 modules"
exit 1
}
# enable PHP5 module
a2enmod php5 > /dev/null
# download drupal source
cd /usr/local/src && wget -O drupal.tar.gz http://ftp.drupal.org/files/projects/{{ drupal_version }}.tar.gz > /dev/null 2>&1
[ $? -eq 0 ] && echo "OK: download drupal source" || {
echo "ERROR: download drupal source"
exit 1
}
# extract drupal files
tar xzf /usr/local/src/drupal.tar.gz -C /var/www/html > /dev/null
[ $? -eq 0 ] && echo "OK: extract drupal files" || {
echo "ERROR: extract drupal files"
exit 1
}
# move drupal files
cd /var/www/html && mv ./drupal* ./drupal > /dev/null
[ $? -eq 0 ] && echo "OK: move drupal files" || {
echo "ERROR: move drupal files"
exit 1
}
# set ownership & permissions
cd /var/www/html/drupal &&
cp sites/default/default.settings.php sites/default/settings.php &&
chmod 666 sites/default/settings.php &&
chmod a+w sites/default
[ $? -eq 0 ] && echo "OK: set required permissions" || {
echo "ERROR: set required permissions"
exit 1
}
# create MySQL database & user
mysql <<EOF
create database {{ drupal_db_name }};
grant all on {{ drupal_db_name }}.* to {{ drupal_db_username }}@localhost identified by '{{ drupal_db_password }}';
EOF
[ $? -eq 0 ] && echo "OK: create drupal database and user" || {
echo "ERROR: create drupal database and user"
exit 1
}
# enable mod_rewrite
a2enmod rewrite > /dev/null 2>&1
# restart web server
service apache2 restart
#
# firewall setup
#
# lock down mysql access from public interface
iptables -I INPUT 1 -j DROP -p tcp --dport 3306 -s 0.0.0.0/0 -d 0.0.0.0/0 --in-interface eth0
iptables-save > /etc/iptables.rules
cat <<EOF>/etc/init.d/firewall
#!/bin/sh
# persist iptables block on public interface access to port 3306 (mysql)
iptables-restore < /etc/iptables.rules
EOF
chmod +X /etc/init.d/firewall
update-rc.d firewall defaults &> /dev/null
echo "OK: install drupal service"
_eof
text_template drupal_result_template
Thank you for provisioning drupal server.
You can now finish its configuration on the following page:
http://{{ drupal_server.ipaddress_public }}/drupal
Please use following credentials for database configuration:
hostname: localhost
username: {{ drupal_db_username }}
password: {{ drupal_db_password }}
database: {{ drupal_db_name }}
You can also login to the server directly via SSH by connecting
to root@{{ drupal_server.ipaddress_public }} using the password:
{{ drupal_server_key.password }}
_eof