【发布时间】:2014-03-05 15:52:53
【问题描述】:
我试图让以下脚本在 GCE 上启动时在 CentOS 实例上运行。 我在实例名称上设置了自定义元数据“启动脚本”,并将以下脚本作为值。
脚本在启动、重启或运行 /usr/share/google/run-startup-scripts 时不会执行,但如果我在实例上本地创建它并在那里执行,则会执行
我遗漏了什么明显的东西?
#! /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
【问题讨论】:
-
我还尝试从存储桶中加载脚本,该存储桶至少在 /var/log/google/log 中向我显示了脚本已下载,但它实际上并未执行任务。我需要从 gcutil 设置权限吗?
-
还在 gcutil 命令中添加了 --service_account_scopes=storage-ro 但仍然没有乐趣
-
我遇到了类似的问题,但是我的脚本在我重新启动后启动,但不是在创建实例时启动....
-
这里有同样的问题,但即使重启选项也不起作用
-
如果有人仍然遇到此问题: 1. 在脚本开头包含“touch hello”命令,并检查文件是否在重新启动后在您的主目录中创建。如果是,则脚本实际上已执行,但由于脚本中的错误而停止。 2. 查看串行日志(可通过 Cloud Console 访问)并在那里搜索“启动”,这可能会为您提供更多关于出现问题的提示。 3. 在 Ubuntu 上,目前有一个错误会阻止启动脚本工作:github.com/GoogleCloudPlatform/compute-image-packages/issues/…
标签: startup google-compute-engine