• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

GCP Compute Startup Script

February 12, 2022

How to add startup and shutdown scripts on GCP Compute Engine.

Startup Script

gcloud compute instances add-metadata servername \
--project project-id \
--zone us-central1-c \
--metadata=startup-script='#! /bin/bash
sudo -i
echo "Time: $(date)" >> /tmp/date.txt'

gcloud compute instances add-metadata servername \ --project project-id \ --zone us-central1-c \ --metadata=startup-script='#! /bin/bash sudo -i echo "Time: $(date)" >> /tmp/date.txt'

Shutdown Script

gcloud compute instances add-metadata servername \
--project project-id \
--zone us-central1-c \
--metadata=shutdown-script='#! /bin/bash
# Shuts down Apache server
/etc/init.d/apache2 stop'

gcloud compute instances add-metadata servername \ --project project-id \ --zone us-central1-c \ --metadata=shutdown-script='#! /bin/bash # Shuts down Apache server /etc/init.d/apache2 stop'

Filed Under: Cloud Tagged With: compute, gcloud, metadata, script, startup

Search This Website

Subscribe Via Email

  • Home
  • About
  • Archives

Copyright © 2023