Skip to content
This repository
Newer
Older
100644 165 lines (130 sloc) 4.6 kb
5d9599a5 »
2011-06-09 First commit
1 <?php
2
3 function createSecurityGroup($ec2) {
4 $opt = array('GroupName' => 'thinkup');
5
6 # $ec2->delete_security_group($opt);
7 $response = $ec2->describe_security_groups($opt);
8
9 if ($response->status != 200) {
10 $ec2->create_security_group('thinkup', 'This is the default security group for ThinkUp.');
11 $perms = array(
12 'GroupName' => 'thinkup',
13 'IpPermissions' => array(
14 array( // Set 0
15 'IpProtocol' => 'tcp',
16 'FromPort' => '22',
17 'ToPort' => '22',
18 'IpRanges' => array(
19 array('CidrIp' => '0.0.0.0/0')
20 )
21 ),
22 array( // Set 1
23 'IpProtocol' => 'tcp',
24 'FromPort' => '80',
25 'ToPort' => '80',
26 'IpRanges' => array(
27 array('CidrIp' => '0.0.0.0/0')
28 )
29 ),
30 array( // Set 2
31 'IpProtocol' => 'tcp',
32 'FromPort' => '443',
33 'ToPort' => '443',
34 'IpRanges' => array(
35 array('CidrIp' => '0.0.0.0/0')
36 )
37 ),
38 )
39 );
40 $response = $ec2->authorize_security_group_ingress($perms);
41 if ($response->status == 200) {
42 return 'thinkup';
43 }
44 }
45
46 }
47
48
49 function createKeyPair($ec2) {
50 # $response = $ec2->delete_key_pair('thinkup');
51
52 $response = $ec2->describe_key_pairs(array(
53 'KeyName' => 'thinkup'
54 ));
55
56 if ($response->status != 200) {
57 $response = $ec2->create_key_pair('thinkup');
58
59 # header('Content-type: application/pem');
60 # header('Content-Disposition: attachment; filename="thinkup.pem"');
61
62 return $response->body->keyMaterial;
63 }
64 }
65
66
67
98152008 »
2011-10-07 Switched to an updated EC2 AMI with existing SSH host key pairs removed
68 function createInstance($ec2, $ami, $userdata_add = '') {
5d9599a5 »
2011-06-09 First commit
69 $password = randomPassword(12);
70 $userdata = getUserdata($password);
71 if (isset($userdata_add)) {
72 $userdata .= $userdata_add;
73 }
74
75 $opt = array(
76 'InstanceType' => 'm1.small',
77 'SecurityGroup' => 'thinkup',
78 'KeyName' => 'thinkup',
79 'InstanceType' => 't1.micro',
80 'UserData' => base64_encode($userdata)
81 );
82
83 $response = $ec2->run_instances($ami, 1, 1, $opt);
84 if ($response->status == 200) {
85 $instance_id = $response->body->instancesSet->item->instanceId;
86 return array($instance_id, $password);
87 }
88 }
89
90 function getServerName($ec2, $instance_id) {
91 $response = $ec2->describe_instances(array(
92 'InstanceId' => $instance_id
93 ));
94 if ($response->status == 200) {
95 $hostname = $response->body->reservationSet->item->instancesSet->item->dnsName;
96 return $hostname;
97 }
98 }
99
100
101 function randomPassword($random_string_length) {
102 $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
103 $string = '';
104 for ($i = 0; $i < $random_string_length; $i++) {
105 $string .= $characters[rand(0, strlen($characters) - 1)];
106 }
107 return $string;
108
109 }
110
111
1180e679 »
2012-02-07 Modified to use version checker download URL
112 function getVersion() {
113 $versioncheck_url = 'http://thinkupapp.com/version_download.php';
114 $json = file_get_contents($versioncheck_url);
115 $obj = json_decode($json);
116
117 $url = $obj->{'url'};
118 $version = $obj->{'version'};
119 return array($url, $version);
120
121 }
122
123
73367545 »
2011-11-09 beta 17 updates
124 function getUserdata($password = '') {
1180e679 »
2012-02-07 Modified to use version checker download URL
125 list($url, $version) = getVersion();
126 $filename = 'thinkup_' . $version . '.zip';
127
5d9599a5 »
2011-06-09 First commit
128 $userdata = <<<EOD
129 #!/bin/bash -ex
130 exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
131
1180e679 »
2012-02-07 Modified to use version checker download URL
132 wget $url --no-check-certificate
133 sudo unzip -d /var/www/ $filename
5d9599a5 »
2011-06-09 First commit
134
135 # config thinkup installer
136 sudo ln -s /usr/sbin/sendmail /usr/bin/sendmail
20675d97 »
2012-02-14 Stop creating blank config, set ownership for entire thinkup director…
137 sudo chown -R www-data /var/www/thinkup
5d9599a5 »
2011-06-09 First commit
138
139 # create database
140 mysqladmin -u root password $password
141 mysqladmin -h localhost -u root -p$password create thinkup
142
73367545 »
2011-11-09 beta 17 updates
143 mysql -h localhost -u root -p$password <<EOF
144 CREATE USER 'thinkup'@'localhost' IDENTIFIED BY '$password';
145 GRANT ALL PRIVILEGES ON thinkup.* TO thinkup@'localhost';
146 EOF
147
d066778c »
2012-02-07 Added phpmyadmin to installation
148 # install and configure phpmyadmin
149 sudo DEBIAN_FRONTEND=noninteractive apt-get install -q -y phpmyadmin
150 sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
151 sudo /etc/init.d/apache2 reload
152
5d9599a5 »
2011-06-09 First commit
153 # add apparmor exception for ThinkUp backup
154 sudo sed -i '
155 /\/var\/run\/mysqld\/mysqld.sock w,/ a\
20675d97 »
2012-02-14 Stop creating blank config, set ownership for entire thinkup director…
156 /var/www/thinkup/data/** rw,
5d9599a5 »
2011-06-09 First commit
157 ' /etc/apparmor.d/usr.sbin.mysqld
158 sudo /etc/init.d/apparmor restart
73367545 »
2011-11-09 beta 17 updates
159
5d9599a5 »
2011-06-09 First commit
160 EOD;
161 return $userdata;
162
163 }
164
165 ?>
Something went wrong with that request. Please try again.