2014-03-05 42 views
3

我试图让以下脚本在启动GCE时在CentOS实例上运行。 我在实例名称和下面的脚本上设置了自定义元数据“startup-script”作为值。谷歌计算引擎启动脚本:启动时没有运行

该脚本不启动时,重新启动执行或当我运行/ usr /共享/谷歌/运行启动的脚本,但如果我实例上的本地创建它不执行和执行有

什么明显我错过了什么?

#! /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 
+0

我也尝试从一个桶中加载脚本,至少在/ var/log/google/log中显示我脚本已下载,但它仍然没有实际执行任务。我需要从gcutil设置权限吗? – mobcdi

+0

还添加了--service_account_scopes = storage-ro到gcutil命令,但仍然没有快乐 – mobcdi

+0

我有类似的问题,但我的脚本启动后,我重新启动,但不是当创建实例时.... – brdido

回答

0

我个人的经验是面临着两个问题:

1)必要的交互命令,将在启动时不正常运行。例如,apt-get install要求您确认过程(是/否)?在这种情况下,你可以关闭的互动,并通过“是”与

yum -y --assumeyes install foo 
apt-get -y --force-yes install foo 

而且更换

yum install foo 
apt-get install foo 

,如果你使用Debian,任何命令之前,以下将打压需求互动:

sudo DEBIAN_FRONTEND=noninteractive <your command here, e.g., apt-get -y install foo> 

2)另一个明显的问题是有时你必须等待进程结束,并且可能远远晚于您的实例显示为“正在运行”发生。

0

我使用CentOS 7作为基础映像并安装了一些库,但它不起作用。切换到CentOS 6后,它运行良好(似乎CentOS 7有问题)。