最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

google cloud platform - Run script after VM creation just once - Stack Overflow

programmeradmin4浏览0评论

I'm using Pulumi on GCP, and I'd like to specify a bash script that would run just once after the VM is created. I saw that compute.Instance has the parameter metadata_startup_script, but IIUC it will run each time the machine boots.

I'm using Pulumi on GCP, and I'd like to specify a bash script that would run just once after the VM is created. I saw that compute.Instance has the parameter metadata_startup_script, but IIUC it will run each time the machine boots.

Share Improve this question edited 10 hours ago Sai Chandini Routhu 1,6781 gold badge5 silver badges15 bronze badges asked 14 hours ago dimiddimid 7,6313 gold badges55 silver badges91 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

Indeed, metadata_startup_script runs every time the machine boots, but you can add set an environment variable (maybe something inside .bashrc like $INIT_RUN=1) the first time you run it, and skip running it when the variable is already set.

The metadata_startup_script in your Compute Engine runs every time the instance boots. But if you want to specify a bash script that would run just once after the VM is created. For this you can use startup scripts with a flag file or cloud -init.

You can use the metadata_startup_script but add logic in the script to check the existence of a flag file. If the flag file exists, the script does nothing immediately. If the flag file doesn’t exist, execute the script and then create the flag file.

Cloud-init is also a very helpful tool for this purpose. Which provides more advanced configuration options for your instances, including running scripts only once.

发布评论

评论列表(0)

  1. 暂无评论