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?