startup - 谷歌计算引擎启动脚本 : Not running on startup

标签 startup google-compute-engine

我试图在 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

最佳答案

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

1) 需要交互的命令在启动时无法正常运行。例如,apt-get install 要求您确认该过程(是/否)?在这种情况下,您可以关闭交互并通过替换来传递"is"

yum install foo
apt-get install foo


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

此外,如果您使用的是 Debian,则在任何命令之前的以下内容将抑制交互需求:
sudo DEBIAN_FRONTEND=noninteractive <your command here, e.g., apt-get -y install foo>

2) 另一个明显的问题是有时您必须等待该过程完成,这可能发生在您的实例显示为“正在运行”之后很久。

关于startup - 谷歌计算引擎启动脚本 : Not running on startup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22202597/

相关文章:

r - 我可以在 R 中缓存数据加载吗?

matlab - 在命令行窗口中禁用 Matlab 中的启动提示?

google-compute-engine - Goland 显示未解析类型(实例,具体在 GCE 库中),但核心/测试运行良好 ("invalidate and restart"解决方案在这里不起作用)

google-cloud-platform - GCP 错误 : Quota 'GPUS_ALL_REGIONS' exceeded. 全局限制 : 0. 0

google-cloud-platform - 如何在 Google Cloud 中请求增加 GPU 配额

黑莓应用程序启动速度非常慢,我该如何解决这个问题?

python - 如何在每次启动Python时运行Python命令

c++ - CC2538 (Cortex m3) 启动时出现硬故障,位于 __lib_init_array 中

java - Google Compute Engine 上 Hadoop 中的标准输出

go - 使用 Go 客户端库创建实例组时无法定义网络?