Stay organized with collections Save and categorize content based on your preferences.
Linux Windows
This document explains how to set the host maintenance policy for a Compute Engine instance to determine its behavior during host events. To learn more about host maintenance policies, see Host maintenance policy.
A host maintenance policy determines how your instance responds when the host on which the instance is running requires maintenance or encounters an error. Configuring the host maintenance policy for an instance helps you do the following:
Minimize downtime.
Prevent data loss.
For host maintenance policies, the following limitations apply:
Virtual machine instances using E2 machine types can only live migrate during host maintenance events, unless they're Spot VMs or preemptible VMs.
The following instances can only stop during host maintenance events:
Instances that don't support live migration, such as Z3 instances with more than 18 TiB of attached Titanium SSD, bare metal instances, or VMs that have GPUs attached.
Spot VMs or preemptible VMs.
Spot VMs and preemptible VMs can't automatically restart after host errors or programmed stops.
Select the tab for how you plan to use the samples on this page:
ConsoleWhen you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloudInstall the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
Note: If you installed the gcloud CLI previously, make sure you have the latest version by runninggcloud components update
.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. After installation, initialize the Google Cloud CLI by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
To get the permissions that you need to set the host maintenance policy for 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 permissions required to set the host maintenance policy for a compute instance. To see the exact permissions that are required, expand the Required permissions section:
Required permissionsThe following permissions are required to set the host maintenance policy for a compute instance:
compute.instances.create
on the projectcompute.images.useReadOnly
on the imagecompute.snapshots.useReadOnly
on the snapshotcompute.instanceTemplates.useReadOnly
on the instance templatecompute.networks.use
on the projectcompute.addresses.use
on the projectcompute.networks.useExternalIp
on the projectcompute.subnetworks.use
on the project or on the chosen subnetcompute.subnetworks.useExternalIp
on the project or on the chosen subnetcompute.instances.setMetadata
on the projectcompute.instances.setTags
on the VMcompute.instances.setLabels
on the VMcompute.instances.setServiceAccount
on the VMcompute.disks.create
on the projectcompute.disks.use
on the diskcompute.disks.useReadOnly
on the diskcompute.instanceTemplates.create
on the projectcompute.instances.setScheduling
on the instanceYou might also be able to get these permissions with custom roles or other predefined roles.
Available host maintenance propertiesYou can customize how your compute instance behaves during scheduled maintenance or unexpected host events. Unless you specify otherwise, Compute Engine uses default settings when you create an instance, instances in bulk, or an instance template.
You can configure the following host maintenance properties:
Maintenance behavior (onHostMaintenance
): what happens to your instance during a maintenance event on its host that might cause the instance to restart. You can set this property to one of the following:
Migrate: Compute Engine automatically live migrates your instance to another host. This is the default setting for all types of instances, except Spot VMs and preemptible VMs.
Important: You must configure instances that don't support live migration to stop (Terminate) during maintenance events. Otherwise, you encounter errors.Terminate: Compute Engine stops your instance. This is the default setting for Spot VMs or preemptible VMs, and it's the only supported setting for Z3 instances with more than 18 TiB of attached Titanium SSD, bare metal instances, and instances with GPUs or TPUs attached.
Automatic restart (automaticRestart
): whether your instance restarts if it crashes or Compute Engine stops it for a programmed stop, such as a maintenance event. You can set this property to one of the following:
On: Compute Engine automatically restarts the instance. This is the default setting for all types of instances, except for Spot VMs and preemptible VMs. You specify this setting as follows:
For the Google Cloud console, in the Advanced pane, in the Automatic restart list, select On (recommended).
For the Google Cloud CLI, use the --restart-on-failure
flag.
For REST, set the automaticRestart
field to true
.
Off: Compute Engine doesn't restart the instance. This is the default setting for Spot VMs or preemptible VMs. You specify this setting as follows:
For the Google Cloud console, in the Advanced pane, in the Automatic restart list, select Off.
For the gcloud CLI, use the --no-restart-on-failure
flag.
For REST, set the automaticRestart
field to false
.
Local SSD data recovery timeout (localSsdRecoveryTimeout
): this setting applies only to instances that have Local SSD disks attached. It determines how long Compute Engine waits to recover data from your Local SSD disks after host errors. By default, this property is unset. You can set this property to one of the following:
Unset: Compute Engine uses the default wait time:
For Z3 VMs, 6 hours
For all other types of instances, 1 hour
An integer from 0 to 168: the number of hours to wait. Setting this property to 0
means that Compute Engine doesn't recover Local SSD data and restarts the instance immediately.
Host error timeout (hostErrorTimeoutSeconds
): this property determines how long Compute Engine waits to restart an unresponsive instance. You must configure this setting before the instance becomes unresponsive. Use a timeout that is long enough for an instance to recover from being unresponsive. You can set this property to one of the following:
Unset: Compute Engine waits up to 330 seconds (5 minutes and 30 seconds). This is the default setting for any type of instance.
An integer from 90 to 330: the wait time in seconds, in increments of 30 seconds.
By default, compute instances use the default settings for their host maintenance policy. To customize these settings, use one of the following methods:
Before you change the host maintenance policy of an existing instance, ensure the following:
You can't change the maintenance behavior (onHostMaintenance
) of the following types of instances:
VMs that use E2 machine types.
Spot VMs or preemptible VMs.
Instances that don't support live migration.
You can't configure Spot VMs or preemptible VMs to automatically restart after host errors or programmed stops.
To change the Local SSD data recovery timeout in an instance that has Local SSD disks attached, use the gcloud CLI or REST API. Otherwise, select any of the following options:
ConsoleIn the Google Cloud console, go to the VM instances page.
In the Name column, click the name of the instance that you want to update. A page that gives the details of the instance appears.
Click edit Edit. A page that lets you edit instance properties appears.
In the Management section, you can do one or more of the following:
To change the behavior during maintenance events, select another option from the On host maintenance list
To change the timeout period before restarting an unresponsive instance, select another option from the Host error timeout list.
To change whether to restart the instance or not after host errors or programmed stops, select another option from the Automatic restart list.
Click Save.
To change the host maintenance policy in an existing instance, use the gcloud compute instances set-scheduling
command with one or more of the following flags:
To change host maintenance behavior, include the --maintenance-policy
flag.
To change automatic restart behavior, do one of the following:
To automatically restart the instance, include the --restart-on-failure
flag.
To prevent the instance from automatically restarting, include the --no-restart-on-failure
flag.
To change the Local SSD data recovery timeout if your instance has Local SSD disks attached, include the --local-ssd-recovery-timeout
flag.
To change the host error timeout, include the --host-error-timeout-seconds
flag.
For example, to change host maintenance behavior, automatically restart the instance after host errors or programmed stops, change the Local SSD data recovery timeout, and change the host error timeout, run the following command:
gcloud compute instances set-scheduling INSTANCE_NAME \
--host-error-timeout-seconds=ERROR_DETECTION_TIMEOUT \
--local-ssd-recovery-timeout=LOCAL_SSD_RECOVERY_TIMEOUT \
--maintenance-policy=MAINTENANCE_POLICY \
--restart-on-failure \
--zone=ZONE
Replace the following:
INSTANCE_NAME
: the name of your instance.
ERROR_DETECTION_TIMEOUT
: the number of seconds before Compute Engine restarts an unresponsive instance. The value must be between 90
(90 seconds) and 330
(330 seconds, or 5 minutes and 30 seconds). Only 30-second increments are allowed.
MAINTENANCE_POLICY
: the maintenance behavior of the instance. The value can be either TERMINATE
or MIGRATE
.
LOCAL_SSD_RECOVERY_TIMEOUT
: the number of hours to spend recovering data from the attached Local SSD disks. The value must be between 0
(0 hours) and 168
(168 hours, or 7 days). Setting this field to 0
means that Compute Engine doesn't recover Local SSD data.
ZONE
: the zone where your instance exists.
To change the host maintenance policy in an existing instance, make a POST
request to the instances.setScheduling
method. In the request body, include one or more of the following fields:
To change host maintenance behavior, include the onHostMaintenance
field.
To change automatic restart behavior, do one of the following:
To automatically restart the instance, include the automaticRestart
field.
To prevent the instance from automatically restarting, include the automaticRestart
field.
To change the Local SSD data recovery timeout if your instance has Local SSD disks attached, include the localSsdRecoveryTimeout
field.
To change the host error timeout, include the hostErrorTimeoutSeconds
field.
For example, to change host maintenance behavior, automatically restart the instance after host errors or programmed stops, change the Local SSD data recovery timeout, and change the host error timeout, make a request as follows:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/setScheduling
{
"automaticRestart": AUTOMATIC_RESTART,
"hostErrorTimeoutSeconds": ERROR_DETECTION_TIMEOUT,
"localSsdRecoveryTimeout": LOCAL_SSD_RECOVERY_TIMEOUT,
"onHostMaintenance": "MAINTENANCE_POLICY"
}
Replace the following:
PROJECT_ID
: the ID of the project where your instance exists.
ZONE
: the zone where your instance exists.
INSTANCE_NAME
: the name of your instance.
AUTOMATIC_RESTART
: the automatic restart behavior of the instance if it crashes or Compute Engine stops it for a programmed stop. Specify one of the following values:
To let Compute Engine automatically restart your instance: true
To prevent automatic restarts: false
ERROR_DETECTION_TIMEOUT
: the number of seconds before restarting an unresponsive instance. The value must be between 90
(90 seconds) and 330
(330 seconds, or 5 minutes and 30 seconds). Only 30-second increments are allowed.
LOCAL_SSD_RECOVERY_TIMEOUT
: the number of hours to spend recovering data from the attached Local SSD disks. The value must be between 0
(0 hours) and 168
(168 hours, or 7 days). Setting this field to 0
means that Compute Engine doesn't recover Local SSD data.
MAINTENANCE_POLICY
: the maintenance behavior of the instance. The value can be either TERMINATE
or MIGRATE
.
You can set the host maintenance policy of a compute instance while creating it.
To set the Local SSD data recovery timeout while creating an instance that has Local SSD disks attached, use the gcloud CLI or REST API. Otherwise, select any of the following options:
ConsoleIn the Google Cloud console, go to the Create an instance page.
In the Name field, enter a name for the instance.
In the Region and Zone fields, specify in which region and zone to create the instance.
Specify the machine type for the instance.
In the navigation menu, click Advanced.
In the Provisioning model section, expand VM provisioning model advanced settings, and then do one or more of the following:
To set the behavior during maintenance events, in the On host maintenance list, select one of the following options:
To migrate the instance during host maintenance events, select Migrate VM instance (recommended).
To stop the instance during host maintenance events, select Terminate VM instance.
To set the timeout period before restarting an unresponsive instance, in the Host error timeout list, select one of the following options:
To not specify a host error timeout, select Unspecified (default).
To specify a host error timeout, select one of the available options, up to 5 minutes and 30 seconds.
To set whether to restart the instance if it crashes or is stopped, In the Automatic restart list, select one of the following options:
To automatically restart the instance after host errors or programmed stops, select On (recommended).
To prevent the instance from automatically restarting after host errors or programmed stops, select Off.
Click Create.
To set the host maintenance policy of an instance while creating it, use the gcloud compute instances create
command with one or more of the following flags:
To set the host maintenance behavior, include the --maintenance-policy
flag.
To set the automatic restart behavior, do one of the following:
To automatically restart the instance, include the --restart-on-failure
flag.
To prevent the instance from automatically restarting, include the --no-restart-on-failure
flag.
To set a Local SSD data recovery timeout if your instance has Local SSD disks attached, include the --local-ssd-recovery-timeout
flag.
To set a host error timeout, include the --host-error-timeout-seconds
flag.
For example, to set the host maintenance behavior, automatically restart the instance after host errors or programmed stops, set a Local SSD data recovery timeout, and set a host error timeout, run the following command:
Important: Spot VMs and preemptible VMs don't support automatic restarts after host errors or programmed stops. If you include the--restart-on-failure
flag when you create these types of VMs, then Compute Engine ignores it. This behavior is the same as using the --no-restart-on-failure
flag.
gcloud compute instances create INSTANCE_NAME \
--host-error-timeout-seconds=ERROR_DETECTION_TIMEOUT \
--local-ssd-recovery-timeout=LOCAL_SSD_RECOVERY_TIMEOUT \
--machine-type=MACHINE_TYPE \
--maintenance-policy=MAINTENANCE_POLICY \
--restart-on-failure \
--zone=ZONE
Replace the following:
INSTANCE_NAME
: the name of the instance.
ERROR_DETECTION_TIMEOUT
: the number of seconds before restarting an unresponsive instance. The value must be between 90
(90 seconds) and 330
(330 seconds, or 5 minutes and 30 seconds). Only 30-second increments are allowed.
LOCAL_SSD_RECOVERY_TIMEOUT
: the number of hours to spend recovering data from the attached Local SSD disks. The value must be between 0
(0 hours) and 168
(168 hours, or 7 days). Setting this field to 0
means that Compute Engine doesn't recover Local SSD data.
MACHINE_TYPE
: the machine type to use.
MAINTENANCE_POLICY
: the maintenance behavior of the instance. The value can be either TERMINATE
or MIGRATE
. If you're creating a Spot VM, preemptible VM, or an instance that doesn't support live migration, then you can only use TERMINATE
.
ZONE
: the zone in which to create the instance.
To set the host maintenance policy of an instance while creating it, make a POST
request to the instances.insert
method. In the request body, include one or more of the following fields in the scheduling
field:
To set the host maintenance behavior, include the onHostMaintenance
field.
To set the automatic restart behavior, do one of the following:
To automatically restart the instance, include the automaticRestart
field.
To prevent the instance from automatically restarting, include the automaticRestart
field.
To set a Local SSD data recovery timeout if your instance has Local SSD disks attached, include the localSsdRecoveryTimeout
field.
To set a host error timeout, include the hostErrorTimeoutSeconds
field.
For example, to set the host maintenance behavior, automatically restart the instance after host errors or programmed stops, set a Local SSD data recovery timeout, and set a host error timeout, make a request as follows:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances
{
"name": "INSTANCE_NAME",
"machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",
"disks": [
{
"boot": true,
"initializeParams": {
"sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
}
}
],
"networkInterfaces": [
{
"network": "global/networks/default"
}
],
"scheduling": {
"automaticRestart": AUTOMATIC_RESTART,
"hostErrorTimeoutSeconds": ERROR_DETECTION_TIMEOUT,
"localSsdRecoveryTimeout": LOCAL_SSD_RECOVERY_TIMEOUT,
"onHostMaintenance": "MAINTENANCE_POLICY"
}
}
Replace the following:
PROJECT_ID
: the ID of the project in which to create the instance.
ZONE
: the zone in which to create the instance.
INSTANCE_NAME
: the name of the instance.
MACHINE_TYPE
: the machine type to use.
IMAGE_PROJECT
: the image project that contains the image—for example, debian-cloud
. For more information about the supported image projects, see Public images.
IMAGE
: specify one of the following:
A specific version of the OS image—for example, debian-12-bookworm-v20240617
.
An image family, which must be formatted as family/IMAGE_FAMILY
. This specifies the most recent, non-deprecated OS image. For example, if you specify family/debian-12
, the latest version in the Debian 12 image family is used. For more information about using image families, see Image families best practices.
AUTOMATIC_RESTART
: the automatic restart behavior of the instance if it crashes or Compute Engine stops it for a programmed stop. Specify one of the following values:
To let Compute Engine automatically restart your instance: true
To prevent automatic restarts: false
ERROR_DETECTION_TIMEOUT
: the number of seconds before restarting an unresponsive instance. The value must be between 90
(90 seconds) and 330
(330 seconds, or 5 minutes and 30 seconds). Only 30-second increments are allowed.
LOCAL_SSD_RECOVERY_TIMEOUT
: the number of hours to spend recovering data from the attached Local SSD disks. The value must be between 0
(0 hours) and 168
(168 hours, or 7 days). Setting this field to 0
means that Compute Engine doesn't recover Local SSD data.
MAINTENANCE_POLICY
: the maintenance behavior of the instance. The value can be either TERMINATE
or MIGRATE
. If you're creating a Spot VM or an instance that doesn't support live migration, then you can only use TERMINATE
.
For more information about creating an instance, see Create and start a Compute Engine instance.
Set the policy while creating instances in bulkTo set the host maintenance policy while creating instances in bulk, select one of the following options:
gcloudTo set the host maintenance policy while creating instances in bulk, use the gcloud compute instances bulk create
command with one or more of the following flags:
To set the host maintenance behavior, include the --maintenance-policy
flag.
To set the automatic restart behavior, do one of the following:
To automatically restart the instance, include the --restart-on-failure
flag.
To prevent the instance from automatically restarting, include the --no-restart-on-failure
flag.
To set a Local SSD data recovery timeout if your instance has Local SSD disks attached, include the --local-ssd-recovery-timeout
flag.
To set a host error timeout, include the --host-error-timeout-seconds
flag.
For example, to set the host maintenance behavior, automatically restart the instance after host errors or programmed stops, set a Local SSD data recovery timeout, and set a host error timeout, run the following command. The following example also creates instances in a single zone and specifies a name pattern for the instances:
Important: Spot VMs and preemptible VMs don't support automatic restarts after host errors or programmed stops. If you include the--restart-on-failure
flag when you create these types of VMs, then Compute Engine ignores it. This behavior is the same as using the --no-restart-on-failure
flag.
gcloud compute instances bulk create \
--count=COUNT \
--host-error-timeout-seconds=ERROR_DETECTION_TIMEOUT \
--local-ssd-recovery-timeout=LOCAL_SSD_RECOVERY_TIMEOUT \
--machine-type=MACHINE_TYPE \
--maintenance-policy=MAINTENANCE_POLICY \
--name-pattern=NAME_PATTERN \
--restart-on-failure \
--zone=ZONE
Replace the following:
COUNT
: the number of instances to create.
ERROR_DETECTION_TIMEOUT
: the number of seconds before restarting an unresponsive instance. The value must be between 90
(90 seconds) and 330
(330 seconds, or 5 minutes and 30 seconds). Only 30-second increments are allowed.
LOCAL_SSD_RECOVERY_TIMEOUT
: the number of hours to spend recovering data from the attached Local SSD disks. The value must be between 0
(0 hours) and 168
(168 hours, or 7 days). Setting this field to 0
means that Compute Engine doesn't recover Local SSD data.
MACHINE_TYPE
: the machine type to use.
MAINTENANCE_POLICY
: the maintenance behavior of the instances. The value can be either TERMINATE
or MIGRATE
. If you're creating Spot VMs, preemptible VMs, or instances that don't support live migration, then you can only use TERMINATE
.
NAME_PATTERN
: the name pattern for the instances. To replace a sequence of numbers in an instance name, use a sequence of hash (#
) characters. For example, using instance-#
for the name pattern generates instances with names starting with instance-1
, instance-2
, and continuing up to the number of instance specified by COUNT
.
ZONE
: the zone in which to create the instances.
To set the host maintenance policy while creating instances in bulk, make a POST
request to the instances.bulkInsert
method. In the request body, include one or more of the following fields in the scheduling
field:
To set the host maintenance behavior, include the onHostMaintenance
field.
To set the automatic restart behavior, do one of the following:
To automatically restart the instance, include the automaticRestart
field.
To prevent the instance from automatically restarting, include the automaticRestart
field.
To set a Local SSD data recovery timeout if your instance has Local SSD disks attached, include the localSsdRecoveryTimeout
field.
To set a host error timeout, include the hostErrorTimeoutSeconds
field.
For example, to set the host maintenance behavior, automatically restart the instance after host errors or programmed stops, set a Local SSD data recovery timeout, and set a host error timeout, make a request as follows. The following example also creates instances in a single zone and specifies a name pattern for the instances:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/bulkInsert
{
"count": COUNT,
"namePattern": "NAME_PATTERN",
"instanceProperties": {
"machineType": "MACHINE_TYPE",
"disks": [
{
"boot": true,
"initializeParams": {
"sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
}
}
],
"networkInterfaces": [
{
"network": "global/networks/default"
}
],
"scheduling": {
"automaticRestart": AUTOMATIC_RESTART,
"hostErrorTimeoutSeconds": ERROR_DETECTION_TIMEOUT,
"localSsdRecoveryTimeout": LOCAL_SSD_RECOVERY_TIMEOUT,
"onHostMaintenance": "MAINTENANCE_POLICY"
}
}
}
Replace the following:
PROJECT_ID
: the ID of the project in which to create the instances.
ZONE
: the zone in which to create the instances.
COUNT
: the number of instances to create.
NAME_PATTERN
: the name pattern for the instances. To replace a sequence of numbers in an instance name, use a sequence of hash (#
) characters. For example, using instance-#
for the name pattern generates instances with names starting with instance-1
, instance-2
, and continuing up to the number of instance specified by COUNT
.
MACHINE_TYPE
: the machine type to use.
IMAGE_PROJECT
: the image project that contains the image—for example, debian-cloud
. For more information about the supported image projects, see Public images.
IMAGE
: specify one of the following:
A specific version of the OS image—for example, debian-12-bookworm-v20240617
.
An image family, which must be formatted as family/IMAGE_FAMILY
. This specifies the most recent, non-deprecated OS image. For example, if you specify family/debian-12
, the latest version in the Debian 12 image family is used. For more information about using image families, see Image families best practices.
AUTOMATIC_RESTART
: the automatic restart behavior of the instance if it crashes or Compute Engine stops it for a programmed stop. Specify one of the following values:
To let Compute Engine automatically restart your instance: true
To prevent automatic restarts: false
ERROR_DETECTION_TIMEOUT
: the number of seconds before restarting an unresponsive instance. The value must be between 90
(90 seconds) and 330
(330 seconds, or 5 minutes and 30 seconds). Only 30-second increments are allowed.
LOCAL_SSD_RECOVERY_TIMEOUT
: the number of hours to spend recovering data from the attached Local SSD disks. The value must be between 0
(0 hours) and 168
(168 hours, or 7 days). Setting this field to 0
means that Compute Engine doesn't recover Local SSD data.
MAINTENANCE_POLICY
: the maintenance behavior of the instances. The value can be either TERMINATE
or MIGRATE
. If you're creating Spot VMs, preemptible VMs, or instances that don't support live migration, then you can only use TERMINATE
.
For more information about creating instances in bulk, see Create VMs in bulk.
Set the policy while creating an instance templateYou can set the host maintenance policy while creating an instance template. All compute instances that you create using the template inherit the host maintenance policy specified in the template.
To set the Local SSD data recovery timeout while creating an instance template that specifies Local SSD disks, use the gcloud CLI or REST API. Otherwise, select any of the following options:
ConsoleIn the Google Cloud console, go to the Instance templates page.
Click Create instance template. The Create instance template page appears.
In the Name field, enter a name for the instance template.
In the Location section, select one of the following options:
To create a regional instance template, select Regional (recommended), and then select the region in which to create the template.
To create a global instance template, select Global.
In the Machine configuration section, specify the machine type for the instance template.
In the Provisioning model section, expand VM provisioning model advanced settings, and then do one or more of the following:
To change the behavior during maintenance events, in the On host maintenance list, select one of the following options:
To migrate the instance during host maintenance events, select Migrate VM instance (recommended).
To stop the instance during host maintenance events, select Terminate VM instance.
To change the timeout period before restarting an unresponsive instance, in the Host error timeout list, select one of the following options:
To not specify a host error timeout, select Unspecified (default).
To specify a host error timeout, select one of the available options, up to 5 minutes and 30 seconds.
To change whether to restart the instance if it crashes or is stopped, In the Automatic restart list, select one of the following options:
To automatically restart the instance after host errors or programmed stops, select On (recommended).
To prevent the instance from automatically restarting after host errors or programmed stops, select Off.
Click Create.
To set the host maintenance policy while creating an instance template, use the gcloud compute instance-templates create
command with one or more of the following flags:
To set the host maintenance behavior, include the onHostMaintenance
field.
To set the automatic restart behavior, do one of the following:
To automatically restart the instance, include the automaticRestart
field.
To prevent the instance from automatically restarting, include the automaticRestart
field.
To set a Local SSD data recovery timeout if your instance has Local SSD disks attached, include the localSsdRecoveryTimeout
field.
To set a host error timeout, include the hostErrorTimeoutSeconds
field.
For example, to set the host maintenance behavior, automatically restart the instance after host errors or programmed stops, set a Local SSD data recovery timeout, and set a host error timeout, run the following command. The following example also creates a regional instance template. To create a global instance template, use the same command without the --instance-template-region
flag.
--restart-on-failure
flag when you create these types of VMs, then Compute Engine ignores it. This behavior is the same as using the --no-restart-on-failure
flag.
gcloud compute instance-templates create INSTANCE_TEMPLATE_NAME \
--host-error-timeout-seconds=ERROR_DETECTION_TIMEOUT \
--instance-template-region=REGION \
--local-ssd-recovery-timeout=LOCAL_SSD_RECOVERY_TIMEOUT \
--machine-type=MACHINE_TYPE \
--maintenance-policy=MAINTENANCE_POLICY \
--restart-on-failure
Replace the following:
INSTANCE_TEMPLATE_NAME
: the name of the instance template.
ERROR_DETECTION_TIMEOUT
: the number of seconds before restarting an unresponsive instance. The value must be between 90
(90 seconds) and 330
(330 seconds, or 5 minutes and 30 seconds). Only 30-second increments are allowed.
REGION
: the region in which to create the instance template.
LOCAL_SSD_RECOVERY_TIMEOUT
: the number of hours to spend recovering data from the attached Local SSD disks. The value must be between 0
(0 hours) and 168
(168 hours, or 7 days). Setting this field to 0
means that Compute Engine doesn't recover Local SSD data.
MACHINE_TYPE
: the machine type to use.
MAINTENANCE_POLICY
: the maintenance behavior of the instances. The value can be either TERMINATE
or MIGRATE
. If you're specifying a Spot VM, preemptible VM, or instance type that doesn't support live migration in the instance template, then you can only use TERMINATE
.
To set the host maintenance policy while creating an instance template, make a POST
request to one of the following methods:
To create a regional instance template: regionInstanceTemplates.insert
method
To create a global instance template: instanceTemplates.insert
method
In the request body, include one or more of the following fields in the scheduling
field:
To set the host maintenance behavior, include the onHostMaintenance
field.
To set the automatic restart behavior, do one of the following:
To automatically restart the instance, include the automaticRestart
field.
To prevent the instance from automatically restarting, include the automaticRestart
field.
To set a Local SSD data recovery timeout if your instance has Local SSD disks attached, include the localSsdRecoveryTimeout
field.
To set a host error timeout, include the hostErrorTimeoutSeconds
field.
For example, to set the host maintenance behavior, automatically restart the instance after host errors or programmed stops, set a Local SSD data recovery timeout, and set a host error timeout, make a request as follows. The following example also creates a regional instance template.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/instanceTemplates
{
"name": "INSTANCE_TEMPLATE_NAME",
"properties": {
"disks": [
{
"boot": true,
"initializeParams": {
"sourceImage": "projects/IMAGE_PROJECT/global/images/IMAGE"
}
}
],
"machineType": "MACHINE_TYPE",
"networkInterfaces": [
{
"network": "global/networks/default"
}
],
"scheduling": {
"automaticRestart": AUTOMATIC_RESTART,
"hostErrorTimeoutSeconds": ERROR_DETECTION_TIMEOUT,
"localSsdRecoveryTimeout": LOCAL_SSD_RECOVERY_TIMEOUT,
"onHostMaintenance": "MAINTENANCE_POLICY"
}
}
}
Replace the following:
PROJECT_ID
: the ID of the project in which to create the instance template.
REGION
: the region in which to create the instance template.
INSTANCE_TEMPLATE_NAME
: the name of the instance template.
IMAGE_PROJECT
: the image project that contains the image—for example, debian-cloud
. For more information about the supported image projects, see Public images.
IMAGE
: specify one of the following:
A specific version of the OS image—for example, debian-12-bookworm-v20240617
.
An image family, which must be formatted as family/IMAGE_FAMILY
. This specifies the most recent, non-deprecated OS image. For example, if you specify family/debian-12
, the latest version in the Debian 12 image family is used. For more information about using image families, see Image families best practices.
MACHINE_TYPE
: the machine type to use.
AUTOMATIC_RESTART
: the automatic restart behavior of the instance if it crashes or Compute Engine stops it for a programmed stop. Specify one of the following values:
To let Compute Engine automatically restart your instance: true
To prevent automatic restarts: false
ERROR_DETECTION_TIMEOUT
: the number of seconds before restarting an unresponsive instance. The value must be between 90
(90 seconds) and 330
(330 seconds, or 5 minutes and 30 seconds). Only 30-second increments are allowed.
LOCAL_SSD_RECOVERY_TIMEOUT
: the number of hours to spend recovering data from the attached Local SSD disks. The value must be between 0
(0 hours) and 168
(168 hours, or 7 days). Setting this field to 0
means that Compute Engine doesn't recover Local SSD data.
MAINTENANCE_POLICY
: the maintenance behavior of the instances. The value can be either TERMINATE
or MIGRATE
. If you're specifying a Spot VM, preemptible VM, or instance type that doesn't support live migration in the instance template, then you can only use TERMINATE
.
For more information about creating an instance template, see Create instance templates.
View host maintenance policy of an instanceYou can view the host maintenance policy of an instance by viewing the instance's details.
When viewing the instance's details using the gcloud CLI or REST API, you can only view the localSsdRecoveryTimeout
and hostErrorTimeoutSeconds
fields if you specified them while creating or updating the instance.
To view the Local SSD data recovery timeout in an instance that has Local SSD disks attached, use the gcloud CLI or REST API. Otherwise, select any of the following options:
ConsoleIn the Google Cloud console, go to the VM instances page.
In the Name column, click the instance that you want to view. A page that gives the details of the instance appears.
On the Details tab, in the Management section, in the Availability policies section, you can view the following:
In the On host maintenance field, you can see the instance's host maintenance behavior events.
In the Host error timeout field, you can see the amount of time the instance waits before restarting or stopping the instance after detecting that it's unresponsive. If the value is unset (—), then the default wait time is 5 minutes and 30 seconds.
In the Automatic restart restart field, you can see whether the instance automatically restarts the instance after it crashes or Compute Engine stops it for a programmed stop.
To view the host maintenance policy for an instance, use the gcloud compute instances describe
command with the --flatten
flag set to scheduling
:
gcloud compute instances describe INSTANCE_NAME \
--flatten=scheduling \
--zone=ZONE
Replace the following:
INSTANCE_NAME
: the name of the instance.
ZONE
: the zone where the instance is located.
The output is similar to the following:
---
scheduling:
automaticRestart: true
hostErrorTimeoutSeconds: 120
localSsdRecoveryTimeout:
nanos: 0
seconds: '10800'
onHostMaintenance: MIGRATE
preemptible: false
provisioningModel: STANDARD
REST
To view the host maintenance policy for an instance, make a GET
request to the instances.get
method. In the request URL, include the fields
query parameter and set it to scheduling
:
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME?fields=scheduling
Replace the following:
PROJECT_ID
: the project where the instance exists.
ZONE
: the zone where the instance exists.
INSTANCE_NAME
: the name of the instance.
The output is similar to the following:
{
"scheduling": {
"onHostMaintenance": "MIGRATE",
"automaticRestart": true,
"preemptible": false,
"provisioningModel": "STANDARD",
"localSsdRecoveryTimeout": {
"seconds": "10800",
"nanos": 0
}
}
}
What's next
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["This document details how to configure the host maintenance policy for virtual machines (VMs) and bare metal instances to manage their behavior during host events."],["You can choose between `MIGRATE` (live migration) or `TERMINATE` (stop and potentially restart) for maintenance events, with `MIGRATE` being the default for most VMs and `TERMINATE` for specific instance types like Z3 and bare metal."],["The `automaticRestart` property determines if an instance restarts after crashing or being stopped, with the default being `true`."],["`localSsdRecoveryTimeout` is used to specify the time Compute Engine waits to recover Local SSD data, up to 168 hours (7 days), while `hostErrorTimeoutSeconds` determines the wait time before an unresponsive instance restarts or terminates, ranging from 90 to 330 seconds."],["Host maintenance policies, including `onHostMaintenance`, `automaticRestart`, `localSsdRecoveryTimeout`, and `hostErrorTimeoutSeconds`, can be set during instance creation or updated on existing instances using the Google Cloud console, gcloud CLI, or REST API."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4