View graceful shutdown in a Compute Engine instance


This document explains how to view the details of a graceful shutdown in a Compute Engine instance. To learn more about graceful shutdown, see Graceful shutdown overview.

Viewing the details of a graceful shutdown helps you monitor the graceful shutdown process or review its settings.

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

    1. Install the Google Cloud CLI, then initialize it by running the following command:

      gcloud init
    2. 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 compute.instances.get on the project permission, which is required to view the graceful shutdown of a compute instance.

You might also be able to get this permission with custom roles or other predefined roles.

View the details of a graceful shutdown

To view the details of a graceful shutdown in a compute instance, select one of the following options:

Console

  1. In the Google Cloud console, go to the VM instances page.

    Go to VM instances

  2. In the Name column, click the name of your instance.

    The details page of the instance opens and the Details tab is selected.

  3. 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.

  4. To monitor an ongoing graceful shutdown, in the Basic information section, check the following fields:

    • Status: this field shows the state of your instance. During a graceful shutdown, it displays Pending stop and a countdown timer showing the time remaining before the graceful shutdown period ends.

    • Target state: this field shows whether Compute Engine is stopping (Stopped) or deleting (Deleted) the instance.

gcloud

To view the details of an instance and its graceful shutdown, 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 is located.

To check your graceful shutdown settings or monitor an ongoing shutdown, do the following:

  • To check the graceful shutdown settings in the instance, view the scheduling field in the output:

    ...
    scheduling:
      ...
      gracefulShutdown:
        enabled: true
        maxDuration:
          seconds: 'MAX_DURATION'
      ...
    ...
    

    This output includes the MAX_DURATION value, which specifies how long the graceful shutdown period lasts in seconds. If you didn't specify a custom shutdown period when enabling graceful shutdown in the instance, then Compute Engine omits the maxDuration field and sets the graceful shutdown period to 10 minutes.

  • To monitor the status of an ongoing graceful shutdown, view the shutdownDetails field in the output:

    ...
    resourceStatus:
      ...
      shutdownDetails:
        maxDuration:
          seconds: 'MAX_DURATION'
        requestTimestamp: 'REQUEST_TIMESTAMP'
        stopState: STOP_STATE
        targetState: TARGET_STATE
    ...
    

    This output includes the following values:

    • MAX_DURATION: the duration of the graceful shutdown period in seconds. After Compute Engine sets STOP_STATE to STOPPING, it deletes the maxDuration field.

    • REQUEST_TIMESTAMP: the timestamp when the STOP_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.

    After Compute Engine finishes stopping the instance, it deletes the shutdownDetails field.

REST

To view the details of an instance and its graceful shutdown, 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 the instance is located.

  • ZONE: the zone where the instance is located.

  • INSTANCE_NAME: the name of the instance.

To check your graceful shutdown settings or monitor an ongoing shutdown, do one of the following:

  • To check the graceful shutdown settings in the instance, view the scheduling field in the output:

    {
      ...
      "scheduling": {
        ...
        "gracefulShutdown": {
          "enabled": true,
          "maxDuration": {
            "seconds": "MAX_DURATION"
          }
        }
      },
      ...
    }
    

    This output includes the MAX_DURATION value, which specifies how long the graceful shutdown period lasts in seconds. If you didn't specify a custom shutdown period when enabling graceful shutdown in the instance, then Compute Engine omits the maxDuration field and sets the graceful shutdown period to 10 minutes.

  • To monitor the status of an ongoing graceful shutdown, view the shutdownDetails field in the output:

    {
      ...
      "resourceStatus": {
        ...
        "shutdownDetails": {
          "maxDuration": {
            "seconds": "MAX_DURATION"
          },
          "requestTimestamp": "REQUEST_TIMESTAMP",
          "stopState": "STOP_STATE",
          "targetState": "TARGET_STATE"
        }
      },
      ...
    }
    

    This output includes the following values:

    • MAX_DURATION: the duration of the graceful shutdown period in seconds. After Compute Engine sets STOP_STATE to STOPPING, it deletes the maxDuration field.

    • REQUEST_TIMESTAMP: the timestamp when the STOP_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.

    After Compute Engine finishes stopping the instance, it deletes the shutdownDetails field.

Metadata server

  1. Connect to the instance.

  2. To view the details of an ongoing graceful shutdown in 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 sets STOP_STATE to STOPPING, it deletes the maxDuration field.

    • REQUEST_TIMESTAMP: the timestamp when the STOP_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.

What's next