- Google Cloud Platform for Architects
- Vitthal Srinivasan Janani Ravi Judy Raj
- 189字
- 2021-06-25 20:48:32
Startup scripts
We can run our own startup scripts from VM instances to perform automatic actions such as updating the system, and sending notifications and so on.

A startup script is specified using metadata keys through the metadata server and can be applied using the console or gcloud command line:
- Once you have set the default region and zone for your instance, you can provide a startup script using the gcloud command line while creating an instance. The script is provided with a—metadata flag:
gcloud compute instances create example-instance --tags http-server --metadata startup-script='#! /bin/bash # Installs apache and a custom homepage # Go to root directory sudo su - # For automatic Updates apt-get update # Install apache apt-get install -y apache2 # Edit index.html file cat <<EOF > /var/www/html/index.html <html><body><h1>Hello World</h1> <p>This page was created from a simple start up script!</p> </body></html> EOF'
- For an already running instance, startup scripts can be added using the add-metadata flag as follows. The path can be a URL as well, which means that the script can also be located from a Cloud Storage bucket object:
gcloud compute instances add-metadata example-instance --metadata-from-file startup-script=path/to/file
推薦閱讀
- 數據存儲架構與技術
- 在你身邊為你設計Ⅲ:騰訊服務設計思維與實戰
- 數據挖掘原理與實踐
- Test-Driven Development with Mockito
- 正則表達式必知必會
- Architects of Intelligence
- 工業大數據分析算法實戰
- 數據驅動:從方法到實踐
- Lego Mindstorms EV3 Essentials
- IPython Interactive Computing and Visualization Cookbook(Second Edition)
- Solaris操作系統原理實驗教程
- 二進制分析實戰
- Doris實時數倉實戰
- MySQL數據庫技術與應用
- R Machine Learning Essentials