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

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  
主站蜘蛛池模板: 密云县| 永州市| 和顺县| 德安县| 木兰县| 祁东县| 九龙坡区| 淮滨县| 霍山县| 门头沟区| 孟津县| 唐海县| 关岭| 会昌县| 沈阳市| 城固县| 都兰县| 鹤峰县| 海丰县| 龙山县| 桦南县| 措勤县| 樟树市| 金沙县| 灯塔市| 大悟县| 青河县| 修水县| 当涂县| 梁山县| 连平县| 普定县| 克拉玛依市| 会昌县| 开原市| 台安县| 河西区| 达日县| 元江| 莎车县| 南投市|