【问题标题】:Unable to run startup script when creating instance on Google Cloud Platform在 Google Cloud Platform 上创建实例时无法运行启动脚本
【发布时间】:2018-01-14 03:42:28
【问题描述】:

我有一个简单的启动脚本,如下所示:

#!/usr/bin/env bash
sudo apt update
sudo apt install -y ruby-full ruby-bundler build-essential

然后像这样在 GCP 上创建 VM 实例:

$ gcloud compute instances create test-app --boot-disk-size=10GB --image-family ubuntu-1604-lts --image-project=ubuntu-os-cloud --machine-type=g1-small --zone europe-west1-b --tags test-server --restart-on-failure --metadata-from-file startup-script=startup.sh

我的startup.sh 是可执行的。我这样设置它的权利:

$ chmod +x startup.sh

当我进入新创建实例的外壳并检查捆绑器时:

test-app:~$ bundle -v

我收到这些消息:

当前未安装程序“bundle”...

那么,这有什么问题,我该如何解决? PS。如果我只从实例 shell 中运行所有命令,一切正常,所以在 GCP 上使用启动脚本会出现一些问题。

【问题讨论】:

    标签: google-compute-engine


    【解决方案1】:

    我用你的用例进行了测试,但是捆绑包安装时没有做任何更改。

    输出: bundle -v Bundler version 1.11.2

    您可以检查 VM 串行控制台日志输出以验证启动脚本是否运行。使用以下命令检查 VM 实例以验证是否已安装软件包:

    sudo apt list --installed | grep -i bundle
    sudo egrep bundle /var/log/dpkg.log
    

    另外,查看gem list bundle

    【讨论】:

      猜你喜欢
      • 2021-01-31
      • 2021-07-15
      • 1970-01-01
      • 2017-04-25
      • 1970-01-01
      • 2020-11-23
      • 1970-01-01
      • 2017-05-23
      • 1970-01-01
      相关资源
      最近更新 更多