Startup scripts and stop scripts

Startup scripts allow you to run a script when starting up or creating an instance. For instance, to always install miniconda and related data science packages when creating a new instance, simply write the following script in a file on your local machine:

#! /bin/bash
apt-get install bzip2
wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh
sudo bash Miniconda2-latest-Linux-x86_64.sh
conda install scikit-learn
conda install pandas
conda install jupyter
conda install ipython

Then as you start the new instance, supply the --metadata-from-file flag, followed by startup-script=PATH/TO/FILE, where PATH/TO/FILE is a relative path to the startup script:

$ gcloud compute instances create example-instance --metadata-from-file startup-script=examples/scripts/install.sh

You can also use a startup script in extension in the command line or from a file stored in Google Storage. For more on startup scripts, visit https://cloud.google.com/compute/docs/startupscript.

Stop scripts are scripts that are automatically run when an instance is terminated or restarted. Similar to startup scripts, you can associate a stop script with an instance at creation by adding the --metadata-from-file flag, followed by shutdown-script=PATH/TO/FILE:

$ gcloud compute instances create example-instance --metadata-from-file shutdown-script=examples/scripts/shutdown.sh
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.11.20