This document gives an overview of the graceful shutdown process in Compute Engine instances. To learn more about the states that an instance can go through during its lifecycle, see Compute Engine instance lifecycle.
When stopping or deleting an instance, Compute Engine allows a short time for the guest OS to fully shut down. If the guest OS doesn't finish running tasks within this time, then Compute Engine forces a shutdown, which can potentially lead to data loss or corrupt file systems.
To prevent these issues, you can enable graceful shutdown in an instance. With this setting enabled, the guest OS has up to one hour to finish running tasks before Compute Engine shuts it down. Graceful shutdown is useful for scenarios when you want to achieve the following:
Allowing a high performance computing (HPC) job to fully shut down.
Allowing a database to finish submitting active transactions.
Allowing an email server to finish processing before shutdown.
Allowing a multiplayer game session to finish running.
About graceful shutdown
The following sections explain how graceful shutdown works.
Shutdown period
In a compute instance, graceful shutdown is disabled by default. You can enable it when creating or updating an instance. When you enable graceful shutdown, you can specify a shutdown period as follows:
Default period: if you don't specify a shutdown period, then Compute Engine uses a default period of 10 minutes.
Custom period: from one second up to one hour.
We recommend choosing a shutdown period that gives your applications enough time to finish running tasks. For example, if you estimate that your applications need 10 minutes to finish running tasks, we recommend specifying a 15-minute shutdown period. This approach prevents tasks from being forcefully stopped and the potential corruption of data. After all tasks in the guest OS have finished running, you can manually end the graceful shutdown to save costs, as described in the next section.
Shutdown process
When you stop or delete a compute instance that has graceful shutdown enabled,
or if Compute Engine stops or deletes it for a scheduled stop or
deletion, the instance state changes to PENDING_STOP
. The graceful shutdown
begins, allowing your applications to finish running their tasks.
Compute Engine ends the graceful shutdown of an instance when the graceful shutdown period times out, or you manually end the graceful shutdown as follows:
From within the guest OS. You stop the instance using the shutdown command of the guest OS; for example,
sudo shutdown -h now
.From Google Cloud. You stop or delete the instance using one of the following methods:
Google Cloud console: complete the following steps:
Go to the VM instances page.
Select the instance, and then click
Stop or Delete.In the dialog that appears, select the Skip graceful shutdown (if applicable) checkbox before confirming to stop or delete the instance.
Google Cloud CLI: include the
--no-graceful-shutdown
flag in the command.REST API: include the
noGracefulShutdown=true
query parameter in the request URL.
When the graceful shutdown process ends, Compute Engine sends the
Advanced Configuration and Power Interface (ACPI) G2 Soft Off signal
to the guest OS, sets the instance state to STOPPING
, and then continues with
the stop or delete operation.
Stopping or deleting without graceful shutdown
After you've enabled graceful shutdown in an instance, you can still stop or delete it without going through the graceful shutdown process. This approach helps you save costs when, for example, you don't need to gracefully shut down your instance on a specific day, or if the workload running on the instance has changed.
To skip graceful shutdown, do one of the following:
Skip graceful shutdown for single operations. Keep graceful shutdown enabled, but bypass it for specific stop or delete operations. To do this, follow the manual shutdown process.
Disable graceful shutdown entirely. If you no longer need to gracefully shut down an instance, then you can disable this feature. For more information, see Disable graceful shutdown in a Compute Engine instance.
Limitations
Graceful shutdown has the following limitations:
You can't enable graceful shutdown in the following compute instances:
Instances that are part of a managed instance group (MIG).
Instances that specify a limited runtime.
After you enable graceful shutdown in an instance, you can't do the following:
You can't update instance properties that require a restart.
If the instance is a TPU VM, then you can't simulate host maintenance events.
If a graceful shutdown is in progress (
PENDING_STOP
), then you can't do the following:You can't update instance properties.
If the instance is being deleted, then you can't enable or disable deletion protection.
Your instance doesn't gracefully shut down, or a graceful shutdown is interrupted, if the following occurs:
Your Spot VM or preemptible instance is preempted.
Your instance has a host maintenance policy set to
TERMINATE
, and Compute Engine stops the instance for a host event.
You can only gracefully shut down and delete up to 8,000 instances at a time per project and per region.
You can gracefully shut down or modify graceful shutdown settings for instances created in bulk only after Compute Engine finishes creating all instances.
Pricing
There is no cost to enable or disable graceful shutdown in a compute instance.
However, when you stop or delete an instance that has graceful shutdown enabled,
you continue to incur charges for the instance as if it was running. These
charges stop when the graceful shutdown period ends and the instance state
changes to STOPPING
.
For more detailed pricing information, see VM instance pricing.