This document explains how to view the settings and progress of a graceful shutdown in a Compute Engine instance. To learn more about graceful shutdown, see Graceful shutdown overview.
When you view the details of an instance, you can do the following:
View graceful shutdown settings. You can verify if graceful shutdown is enabled and how long it lasts.
Monitor graceful shutdown. When a graceful shutdown is in progress, you can check the following:
When the graceful shutdown process times out.
If a stop or delete operation is in progress.
Before you begin
-
If you haven't already, then set up authentication.
Authentication is
the process by which your identity is verified for access to Google Cloud services and APIs.
To run code or samples from a local development environment, you can authenticate to
Compute Engine by selecting one of the following options:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
Required roles
To get the permission that you need to view the graceful shutdown of a compute instance,
ask your administrator to grant you the
Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1
) IAM role on your project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
This predefined role contains the
permission,
which is required to
view the graceful shutdown of a compute instance.
compute.instances.get
on the project
You might also be able to get this permission with custom roles or other predefined roles.
View graceful shutdown settings
To view the graceful shutdown settings in a compute instance, select one of the following options:
Console
In the Google Cloud console, go to the VM instances page.
In the Name column, click the name of your instance.
The details page of the instance opens on the Details tab.
To check the graceful shutdown settings, in the Availability policies section, check the value of the Graceful shutdown maximum duration field. This field shows the graceful shutdown period. If it shows a hyphen (-), then graceful shutdown is disabled.
gcloud
To view the graceful shutdown settings in an instance, use the
gcloud beta compute instances describe
command:
gcloud beta compute instances describe INSTANCE_NAME \
--zone=ZONE
Replace the following:
INSTANCE_NAME
: the name of the instance.ZONE
: the zone where the instance exists.
If graceful shutdown is enabled, then the output is similar to the following:
...
scheduling:
...
gracefulShutdown:
enabled: true
maxDuration:
seconds: 'MAX_DURATION'
...
...
The output includes the MAX_DURATION
value. This value
indicates how long the graceful shutdown period lasts in seconds. If you
didn't specify a custom shutdown period when you enabled graceful shutdown
in the instance, then Compute Engine omits the maxDuration
field
and sets the graceful shutdown period to 10 minutes.
REST
To view the graceful shutdown settings in an instance, make a GET
request
to
beta instances.get
method:
GET https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME
Replace the following:
PROJECT_ID
: the ID of the project where you created the instance.ZONE
: the zone where the instance exists.INSTANCE_NAME
: the name of the instance.
If graceful shutdown is enabled, then the output is similar to the following:
{
...
"scheduling": {
...
"gracefulShutdown": {
"enabled": true,
"maxDuration": {
"seconds": "MAX_DURATION"
}
}
},
...
}
The output includes the MAX_DURATION
value. This value
indicates how long the graceful shutdown period lasts in seconds. If you
didn't specify a custom shutdown period when you enabled graceful shutdown
in the instance, then Compute Engine omits the maxDuration
field
and sets the graceful shutdown period to 10 minutes.
Monitor graceful shutdown
To monitor an ongoing graceful shutdown in a compute instance, select one of the following options:
Console
In the Google Cloud console, go to the VM instances page.
In the Name column, click the name of your instance.
The details page of the instance opens on the Details tab.
If a graceful shutdown is in progress, then, in the Basic information section, check the following fields:
Status: this field shows the state of your instance. During a graceful shutdown, this field displays Pending stop and a countdown timer. The timer counts down to the moment when the graceful shutdown ends.
Target state: this field shows whether Compute Engine is stopping (Stopped) or deleting (Deleted) the instance.
gcloud
To monitor an ongoing graceful shutdown in an instance, use the
gcloud beta compute instances describe
command:
gcloud beta compute instances describe INSTANCE_NAME \
--zone=ZONE
Replace the following:
INSTANCE_NAME
: the name of the instance.ZONE
: the zone where the instance exists.
If a graceful shutdown is in progress, then the output is similar to the following:
...
resourceStatus:
...
shutdownDetails:
maxDuration:
seconds: 'MAX_DURATION'
requestTimestamp: 'REQUEST_TIMESTAMP'
stopState: STOP_STATE
targetState: TARGET_STATE
...
status: PENDING_STOP
...
This output includes the following values:
MAX_DURATION
: the duration of the graceful shutdown period in seconds. After Compute Engine setsSTOP_STATE
toSTOPPING
, it deletes themaxDuration
field.REQUEST_TIMESTAMP
: the timestamp when theSTOP_STATE
started.STOP_STATE
: the stopping phase of the instance. The value can be one of the following:PENDING_STOP
: Compute Engine has started the graceful shutdown. The instance remains in this state until you manually end the graceful shutdown or the graceful shutdown period times out.STOPPING
: the graceful shutdown has ended, and Compute Engine continues with the stop or delete operation.
TARGET_STATE
: whether Compute Engine is stopping (STOPPED
) or deleting (DELETED
) the instance.
If a stop operation is running, then, after Compute Engine sets the
status
field to TERMINATE
, it deletes the shutdownDetails
field.
REST
To monitor an ongoing graceful shutdown in an instance, make a GET
request
to the
beta instances.get
method:
GET https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME
Replace the following:
PROJECT_ID
: the ID of the project where you created the instance.ZONE
: the zone where the instance exists.INSTANCE_NAME
: the name of the instance.
If a graceful shutdown is in progress, then the output is similar to the following:
{
...
"resourceStatus": {
...
"shutdownDetails": {
"maxDuration": {
"seconds": "MAX_DURATION"
},
"requestTimestamp": "REQUEST_TIMESTAMP",
"stopState": "STOP_STATE",
"targetState": "TARGET_STATE"
}
},
...
"status": "PENDING_STOP",
...
}
This output includes the following values:
MAX_DURATION
: the duration of the graceful shutdown period in seconds. After Compute Engine setsSTOP_STATE
toSTOPPING
, it deletes themaxDuration
field.REQUEST_TIMESTAMP
: the timestamp when theSTOP_STATE
started.STOP_STATE
: the stopping phase of the instance. The value can be one of the following:PENDING_STOP
: Compute Engine has started the graceful shutdown. The instance remains in this state until you manually end the graceful shutdown or the graceful shutdown period times out.STOPPING
: the graceful shutdown has ended, and Compute Engine continues with the stop or delete operation.
TARGET_STATE
: whether Compute Engine is stopping (STOPPED
) or deleting (DELETED
) the instance.
If a stop operation is running, then, after Compute Engine sets the
status
field to TERMINATE
, it deletes the shutdownDetails
field.
Metadata server
Connect to the instance.
Query the metadata server:
curl "http://metadata.google.internal/computeMetadata/v1/instance/shutdown-details/?recursive=true?alt=json" \-H "Metadata-Flavor: Google"
If a graceful shutdown is in progress, then the output is similar to the following:
{ "maxDuration": "MAX_DURATION", "requestTimestamp": "REQUEST_TIMESTAMP", "stopState": "STOP_STATE", "targetState": "TARGET_STATE" }
The output includes the following values:
MAX_DURATION
: the duration of the graceful shutdown period in seconds. After Compute Engine setsSTOP_STATE
toSTOPPING
, it deletes themaxDuration
field.REQUEST_TIMESTAMP
: the timestamp when theSTOP_STATE
started.STOP_STATE
: the stopping phase of the instance. The value can be one of the following:PENDING_STOP
: Compute Engine has started the graceful shutdown. The instance remains in this state until you manually end the graceful shutdown or the graceful shutdown period times out.STOPPING
: the graceful shutdown has ended, and Compute Engine continues with the stop or delete operation.
TARGET_STATE
: whether Compute Engine is stopping (STOPPED
) or deleting (DELETED
) the instance.