appsembler / sultan

An Open edX Remote Devstack Toolkit
GNU Affero General Public License v3.0
7 stars 4 forks source link

instances not automatically shutting off #51

Closed thraxil closed 3 years ago

thraxil commented 3 years ago

I noticed that an instance I created last week was still running, despite the addition of the ALIVE_TIME. The issue appears to be that the startup-script metadata doesn't accept a direct command, it's expecting some text that it wants to write to a file like /tmp/metadata-scripts.../startup-script.sh and then execute that.

Steps to reproduce:

GCEMetadataScripts: Starting startup scripts (version 20201217.02-0ubuntu1~18.04.0).
GCEMetadataScripts: Found startup-script in metadata.
GCEMetadataScripts: startup-script: /tmp/metadata-scripts105166155/startup-script: line 1: /bin/bash -c '( sleep 21600; sudo poweroff -p --no-wall ) &': No such file or directory
GCEMetadataScripts: startup-script exit status 127
GCEMetadataScripts: Finished running startup scripts.

I was able to do a very simple

$ gcloud compute instances create example-instance \
  --metadata=startup-script='#!/bin/bash
sleep 60 && poweroff -p --no-wall' --project=appsembler-devstack-30

And verified that that created a VM that turned itself off after a minute. I tried a few variations on getting that into the command in sultan's instance.sh but couldn't get it to work right with the bash escaping in that context.

iamjazzar commented 3 years ago

@thraxil You're right, I did some debugging and the instances are shutting down when I revert #47. Why did we have that change in the first place?

Here's what I've tried (I made it look like the script in instance.sh as possible)

#!/bin/bash

ALIVE_TIME=45
INSTANCE_NAME=example-instance
PROJECT_ID=appsembler-devstack-30
ZONE=us-central1-c

cmd=(
  "gcloud" "compute" "instances" "create" "$INSTANCE_NAME"
  "--project=$PROJECT_ID"
  "--zone=$ZONE"
  "--metadata=startup-script=/bin/bash -c '( sleep $ALIVE_TIME; sudo poweroff -p --no-wall ) &'"
)

"${cmd[@]}"

gcloud beta compute ssh --zone "$ZONE" "$INSTANCE_NAME" --project "$PROJECT_ID"
# sudo journalctl -u google-startup-scripts.service
# gcloud compute instances delete example-instance --project=appsembler-devstack-30
thraxil commented 3 years ago

@ahmedaljazzar I made #47 because on my machine ./sultan devstack create was failing with ERROR: (gcloud) unrecognized arguments: -c