I'm trying to get the following script to run on a CentOS instance at start up on GCE. I have the custom metadata "startup-script" set on the instance name and the following script as the value.
The script isn't executing on startup, reboot or when I run /usr/share/google/run-startup-scripts but does execute if I create it locally on the instance and execute there
What obvious thing am I missing?
#! /bin/bash
# Installs apache and a custom homepage
# 1234567 123456
#Get this servers name from the metadata server and use the header to authenticate
THIS_SERVER_NAME=$(curl http://metadata/computeMetadata/v1/instance/hostname -H "X-Google-Metadata-Request: True")
#Turn off IPtables firewall that comes installed
service iptables stop
#Install apache
yum install -y httpd
#start apache
service httpd start
#create custom default homepage for this server
cat <<EOF > /var/www/html/index.html
<html><body><h1>Hello World</h1>
<p>This is Server: $THIS_SERVER_NAME</p>
</body></html>
EOF