官术网_书友最值得收藏!

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:

  1. 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'
  1. 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  
主站蜘蛛池模板: 五常市| 田阳县| 会东县| 仁寿县| 巴彦县| 连江县| 建始县| 丹棱县| 临武县| 顺平县| 密山市| 尚志市| 扬中市| 阿鲁科尔沁旗| 富顺县| 平南县| 大厂| 怀仁县| 阿合奇县| 凌海市| 延吉市| 梅河口市| 横峰县| 陈巴尔虎旗| 临汾市| 肇庆市| 汾阳市| 乡城县| 伊川县| 武功县| 龙岩市| 错那县| 隆子县| 蒲江县| 长岭县| 旬邑县| 大石桥市| 旬阳县| 新巴尔虎左旗| 措美县| 饶阳县|