Google cloud compute VM startup script got interrupted and does not finish

155 views Asked by At

I followed this guide in order to create self deleting virtual machine after 60 seconds with the following script calling it from a python script. Bellow you can find the startup script:

#!/bin/bash
echo Start the startup script
sleep 60s
echo BEFORE Deleting the VMs after max running time
export NAME="$(curl -X GET http://metadata.google.internal/computeMetadata/v1/instance/name -H 'Metadata-Flavor: Google')"
export ZONE="$(curl -X GET http://metadata.google.internal/computeMetadata/v1/instance/zone -H 'Metadata-Flavor: Google')"
echo AFTER Deleting the VMs after max running time
gcloud --quiet compute instances delete $NAME --zone=$ZONE

Here is how it was triggered from the python code:

        cmd = """gcloud compute instances create-with-container \
            {0} \
            --project={1} \
            --zone=us-central1-c \
            --container-image=gcr.io/project/image \
            --machine-type={2} \
            --scopes "bigquery","gke-default","storage-full","compute-rw" \
            --boot-disk-size {3} \
            --boot-disk-type "pd-ssd" \
            --container-env YAML={4},DATE={5},BUCKET={6} \
            --service-account "{7}" \
            --metadata-from-file=startup-script=startup.sh \
            --description="{8}"
            """.format(vm,
                       gcp,
                       machine,
                       disk_size,
                       yamlup,
                       self.partition,
                       bucket_name,
                       serviceaccount,
                       description
                       )

On the google cloud compute engine, I can see the first echo appear in the logs: "Start the startup script" but after the sleep nothing happens. I am also not even sure if the sleep command works. Is there anything missing?

0

There are 0 answers