forked from pon-prisma/heat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.template
164 lines (160 loc) · 5.38 KB
/
mysql.template
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
heat_template_version: 2013-05-23
description: Deploy a single compute instance with MySQL + Volume (symbolic link)
parameters:
key_name:
type: string
description: Name of a KeyPair
vm_name:
type: string
label: VM name
image_id:
type: string
label: Image ID
description: Image to be used for compute instance
instance_type:
type: string
label: Instance Type
description: Type of instance (flavor) to be used
default: small.bronze
availability_zone:
type: string
description: The Availability Zone to launch the instance.
default: nova
scheduler_hints:
type: string
description: The Host Aggregate to launch the instance in form of '{host:myhost}'.
default: nova
security_groups:
type: comma_delimited_list
description: List of security group names or IDs
default: [dbaas]
net_id:
type: string
description: ID of public (or private) sub network into which servers get deployed
db_name:
type: string
description: Database name
db_username:
type: string
description: Database admin account username
db_password:
type: string
description: Database admin account password
hidden: true
db_root_password:
type: string
description: Root password for MySQL
hidden: true
volume_size:
type: number
description: Size of the volume to be created.
default: 1
device_name:
type: string
description: Device name used by Openstack, currently other name does not work
default: /dev/vdc
mountpoint:
type: string
description: The directory to provide to the user
default: /mnt/workingdir
volume_type:
type: string
description: Type of volume to be used (encrypted or not)
default: data
port:
type: string
description: port for MySQL
resources:
my_instance:
type: OS::Nova::Server
properties:
name: { get_param: vm_name }
key_name: { get_param: key_name }
image: { get_param: image_id }
availability_zone: { get_param: availability_zone }
flavor: { get_param: instance_type }
networks:
- port: { get_resource: server1_port }
user_data:
str_replace:
template: |
#!/bin/bash -v
sudo su -
apt-get update
debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
apt-get -y install mysql-server
# Setting bind address to mysql remote access
sed -i "s/127.0.0.1/0.0.0.0/g" /etc/mysql/my.cnf
sudo service mysql restart
sudo service mysql stop
#Allow user to use volume
mkdir -p mountpoint
mkfs.ext4 device_name
mount device_name mountpoint
#Change MySQL datadir
sudo chown -R mysql:mysql mountpoint
sudo cp -R -p /var/lib/mysql mountpoint
sed -i "s:^datadir.*$:datadir\t\t= mountpoint:" /etc/mysql/my.cnf
sed -i "s:/var/lib/mysql:mountpoint:g" /etc/apparmor.d/usr.sbin.mysqld
/etc/init.d/apparmor reload
/etc/init.d/apparmor restart
mysql_install_db --datadir=mountpoint
sudo service mysql restart
# Setup MySQL root password
mysqladmin -u root password db_rootpassword
# Create a user and the DB
cat << EOF | mysql -u root --password=db_rootpassword
CREATE DATABASE db_name;
GRANT ALL PRIVILEGES ON db_name.* TO "db_user"@"localhost" IDENTIFIED BY "db_password";
GRANT ALL PRIVILEGES ON db_name.* TO "db_user"@"%" IDENTIFIED BY "db_password";
FLUSH PRIVILEGES;
EXIT
EOF
chmod +x /etc/init.d/mysql
update-rc.d mysql defaults
exit
params:
db_rootpassword: { get_param: db_root_password }
db_name: { get_param: db_name }
db_user: { get_param: db_username }
db_password: { get_param: db_password }
mountpoint: { get_param: mountpoint }
device_name: { get_param: device_name }
cinder_volume:
type: OS::Cinder::Volume
properties:
size: { get_param: volume_size }
availability_zone: { get_param: availability_zone }
volume_type: { get_param: volume_type }
volume_attachment:
type: OS::Cinder::VolumeAttachment
properties:
volume_id: { get_resource: cinder_volume }
instance_uuid: { get_resource: my_instance }
mountpoint: { get_param: device_name }
server1_port:
type: OS::Neutron::Port
properties:
network_id: { get_param: net_id }
security_groups: { get_param: security_groups }
outputs:
vmIp:
description: The IP address of the deployed instance
value: { get_attr: [my_instance, first_address] }
vmUuid:
description: Resource ID assigned to the newly created instance
value: { get_resource: my_instance }
vmName:
description: vm name
value: { get_param: vm_name }
serviceType:
description: List of services and ports to be monitored
value:
str_replace:
template: mysql:port
params:
port: { get_param: port }
volumeUuid:
description: Resource ID assigned to the newly created volume attached to instance
value: { get_resource: cinder_volume }