I am using the following start up script in CentOS7 VM in GCP. The url is accessible after first reboot. But if I reboot my machine or stop and then start the machine the machine is not accessible and the url also doesn't work. I though this may be due to selinux so I added the code to disable selinux, but still same results. I tried this by creating multiple new VMs but looks like there is something which I am not able to figure out. When I manually execute this script on the VM and try multiple reboot, I didn't faced any issue.
#!/bin/bash -xe
# introducing sleep so network interfaces and routes can get ready before fetching software
sleep 10
if rpm -q --quiet httpd ; then
echo "installed"
else
yum update -y
yum install -y httpd php php-common
setenforce 0
sed -i.bak -e 's/^SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
cat > /var/www/html/index.php <<'EOF'
<?php
function metadata_value($value) {
$opts = array(
"http" => array(
"method" => "GET",
"header" => "Metadata-Flavor: Google"
)
);
$context = stream_context_create($opts);
$content = file_get_contents("http://metadata/computeMetadata/v1/$value", false, $context);
return $content;
}
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == "http") {
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);
exit();
}
?>
<!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">
<img src="/assets/gcp-logo.svg"/>
<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
mkdir -p /var/www/html/group1 && cp /var/www/html/index.php /var/www/html/group1/index.php
systemctl enable httpd
systemctl restart httpd
fi
On console I can see the below output
serialport: Connected to mytower.us-central1-a.centos7 port 1 (session ID: 405c4d17b926f0906f45a53784d4abd379d6480d, active connections: 1).
DS - 0000000000000030, ES - 0000000000000030, FS - 0000000000000030
GS - 0000000000000030, SS - 0000000000000030
CR0 - 0000000080010033, CR2 - 0000000000000000, CR3 - 00000000BF401000
CR4 - 0000000000000668, CR8 - 0000000000000000
DR0 - 0000000000000000, DR1 - 0000000000000000, DR2 - 0000000000000000
DR3 - 0000000000000000, DR6 - 00000000FFFF0FF0, DR7 - 0000000000000400
GDTR - 00000000BF3EEA98 0000000000000047, LDTR - 0000000000000000
IDTR - 00000000BEE1F018 0000000000000FFF, TR - 0000000000000000
FXSAVE_STATE - 00000000BFF39AB0
!!!! Find image based on IP(0xBF2E6D5C) /build/work/af60adde42b1d1ad5be2a01e4924bb905248/google3/blaze-out/k8-opt/genfiles/third_party/edk2/ovmf_x64_csm_debug_workspace_dir/ovmf_x64_csm_debug_edk2_files_dir/Build/OvmfX64/DEBUG_CLANG38/X64/OvmfPkg/8254TimerDxe/8254Timer/DEBUG/Timer.dll (ImageBase=00000000BF2E5000, EntryPoint=00000000BF2E6AB5) !!!!
Has anyone facing such issue? Request to help me figure out why the VM is not accessible after reboot.
Thanks