Skip to content

Instantly share code, notes, and snippets.

@sinmetal
Last active May 21, 2018 03:42
Show Gist options
  • Save sinmetal/2f550aa6530d82e4c1a1b3186c3f9d88 to your computer and use it in GitHub Desktop.
Save sinmetal/2f550aa6530d82e4c1a1b3186c3f9d88 to your computer and use it in GitHub Desktop.
適当にコマンドを実行し、自ら死ぬインスタンスを生成するstartup-script
#!/bin/bash
# Install google-fluentd
curl -sSO https://dl.google.com/cloudagents/install-logging-agent.sh
sha256sum install-logging-agent.sh
sudo bash install-logging-agent.sh
# Restart google-fluentd
service google-fluentd restart
# Your Task
echo "Start Task!"
echo "DONE Task!"
# Delete Me
INSTANCE_NAME=$(curl http://metadata/computeMetadata/v1/instance/name -H "Metadata-Flavor: Google")
INSTANCE_ZONE=$(curl http://metadata/computeMetadata/v1/instance/zone -H "Metadata-Flavor: Google")
IFS='/'
set -- $INSTANCE_ZONE
INSTANCE_ZONE=$4
echo $INSTANCE_ZONE
yes | gcloud compute instances delete $INSTANCE_NAME --zone $INSTANCE_ZONE
@sinmetal
Copy link
Author

sinmetal commented Feb 8, 2017

最も小さいインスタンスで、全てのScopeを与えたインスタンスを利用する場合のcommand

gcloud compute instances create "ephemeral" --zone "us-central1-b" --machine-type "f1-micro" --scopes "https://www.googleapis.com/auth/cloud-platform" --metadata-from-file startup-script=ephemeral.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment