-
Notifications
You must be signed in to change notification settings - Fork 12
/
gceme.sh.tpl
110 lines (105 loc) · 2.77 KB
/
gceme.sh.tpl
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
#!/bin/bash -xe
apt-get update
apt-get install -y apache2 libapache2-mod-php
# install lookbusy script to test autoscaling
apt-get install -y build-essential git
cd /tmp
git clone https://github.com/beloglazov/cpu-load-generator.git
./cpu-load-generator/install-lookbusy.sh
cd -
cat > /var/www/html/index.php <<'EOF'
<?php
function metadata_value($value) {
$opts = [
"http" => [
"method" => "GET",
"header" => "Metadata-Flavor: Google"
]
];
$context = stream_context_create($opts);
$content = file_get_contents("http://metadata/computeMetadata/v1/$value", false, $context);
return $content;
}
?>
<!doctype html>
<html>
<head>
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.0/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.0/js/materialize.min.js"></script>
<title>Frontend Web Server</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col s2"> </div>
<div class="col s8">
<div class="card blue">
<div class="card-content white-text">
<div class="card-title">Backend that serviced this request</div>
</div>
<div class="card-content white">
<table class="bordered">
<tbody>
<tr>
<td>Name</td>
<td><?php printf(metadata_value("instance/name")) ?></td>
</tr>
<tr>
<td>ID</td>
<td><?php printf(metadata_value("instance/id")) ?></td>
</tr>
<tr>
<td>Hostname</td>
<td><?php printf(metadata_value("instance/hostname")) ?></td>
</tr>
<tr>
<td>Zone</td>
<td><?php printf(metadata_value("instance/zone")) ?></td>
</tr>
<tr>
<td>Machine Type</td>
<td><?php printf(metadata_value("instance/machine-type")) ?></td>
</tr>
<tr>
<td>Project</td>
<td><?php printf(metadata_value("project/project-id")) ?></td>
</tr>
<tr>
<td>Internal IP</td>
<td><?php printf(metadata_value("instance/network-interfaces/0/ip")) ?></td>
</tr>
<tr>
<td>External IP</td>
<td><?php printf(metadata_value("instance/network-interfaces/0/access-configs/0/external-ip")) ?></td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="card blue">
<div class="card-content white-text">
<div class="card-title">Proxy that handled this request</div>
</div>
<div class="card-content white">
<table class="bordered">
<tbody>
<tr>
<td>Address</td>
<td><?php printf($_SERVER["HTTP_HOST"]); ?></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="col s2"> </div>
</div>
</div>
</html>
EOF
sudo mv /var/www/html/index.html /var/www/html/index.html.old
[[ -n "${PROXY_PATH}" ]] && mkdir -p /var/www/html/${PROXY_PATH} && cp /var/www/html/index.php /var/www/html/${PROXY_PATH}/index.php
systemctl enable apache2
systemctl restart apache2