google-compute-engine,startup-scripts"/>

I've added a bash script in instance metadata which performs some tests and then runs the following command at the end of the script.

shutdown -h now

The instance and image is after removed, by the "spawning script".

The instance becomes unavailable via SSH but it does not set it to TERMINATED until like 10 minutes later. During this time it still displays as RUNNING.

Everything looks at it should in the serial console.

Aug  5 16:54:20 database-integrity-test systemd[1]: Stopping Session 1 of user my-user.
Aug  5 16:54:20 database-integrity-test systemd[1]: Stopping User Manager for UID 1001...
Stopping Authenticate and Authorize Users to Run Privileged Tasks...
[[0;32m  OK  [0m] Closed Load/Save RF Kill Switch Status /dev/rfkill Watch.
[[0;32m  OK  [0m] Stopped target Mail Transport Agent.
[[0;32m  OK  [0m] Stopped target Timers.
Aug  5 16:54:20 database-integrity-test systemd[1]: Stopping Authenticate and Authorize Users to Run Privileged Tasks...
[[0;32m  OK  [0m] Stopped Daily Cleanup of Temporary Directories.
[[0;32m  OK  [0m] Stopped target Graphical Interface.
Aug  5 16:54:20 database-integrity-test systemd[1]: Closed Load/Save RF Kill Switch Status /dev/rfkill Watch.
Stopping Accounts Service...
Stopping ACPI event daemon...
[[0;32m  OK  [0m] Stopped target Cloud-init target.
Aug  5 16:54:20 database-integrity-test systemd[1]: Stopped target Mail Transport Agent.
Aug  5 16:54:20 database-integrity-test systemd[1]: Stopped target Timers.
Aug  5 16:54:20 database-integrity-test systemd[1]: Stopped Daily Cleanup of Temporary Directories.
Aug  5 16:54:20 database-integrity-test systemd[1]: Stopped target Graphical Interface.
Aug  5 16:54:20 database-integrity-test systemd[1]: Stopping Accounts Service...
Aug  5 16:54:20 database-integrity-test systemd[1]: Stopping ACPI event daemon...
Aug  5 16:54:20 database-integrity-test systemd[1]: Stopped target Cloud-init target.
and so on . . . .

We want to minimize the upkeep of these "preemtible integrity test instances" to save costs, the test takes a couple of minutes for small databases. Waiting for shutdown to finish 10 or 20 times longer than the actual test adds up after time.

A solution would be to communicate with the instance and terminate it via the Google Cloud API, but i would like to avoid this.

Has anyone else experienced this problem?

Answer

For what you are trying to accomplish, I think it would be best to have the instance complete its task and then use the Google GCE API to delete the instance afterwards. This way, you can use the script remotely and have other functionality as well.

Additionally, you can continue to use the bash script in the instance metadata to delete the instance after its completed its job. However, their are potential latency issues like the one you have outlined; Which is why it would be best to use the API instead.

I would also suggest reviewing the following documents as well:

  1. Storing and retrieving instance metadata documentation

  2. Accessing Instance Metadata

  • 0
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions