You can reset an instance to return a virtual machine instance to its initial state, or restart a previously terminated instance.
Before you begin
- If you want to use the command-line examples in this guide:
- Install the gcloud command-line tool.
- Set a default region and zone.
- If you want to use the API examples in this guide, set up API access.
Resetting an instance
Performing a reset on your instance is similar to pressing the reset button
on your computer, which wipes the memory contents of the machine and
resets the virtual machine to its initial state. The instance remains in
RUNNING
state through the reset.
You can perform a reset on a running instance by using the Reset button
in the GCP Console, the
instances reset
command in
gcloud
, or by making a POST
request in the API.
Console
- Go to the VM Instances page in the Google Cloud Platform Console.
- Check the boxes next to one or more instances that you want to reset.
- At the top right-hand of the page, click the Reset button to reset the instances.
gcloud
To reset your instance using gcloud compute
:
gcloud compute instances reset example-instance
API
In the API, make a POST
request to the following URI, replacing the
project, zone, and instance name appropriately:
https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/instances/example-instance/reset
To reset your instance using the client libraries, construct a request
to the instances().reset
method:
def resetInstance(auth_http, gce_service):
request = gce_service.instances().reset(project="myproject", zone="us-central1-a", instance="example-instance")
response = request.execute(auth_http)
print response
For more information on this method, see the instances().reset
reference documentation.
After running the reset
command, the subsequent
zone operation will return
as DONE
once the instance has completely shut down.
Restarting a stopped instance
If you have
stopped
a virtual machine instance, you can restart the instance with its original
configuration, using the
instances().start
method.
This method boots up a powered-down virtual machine instance that
is currently in a TERMINATED
state.
The start
method restarts an instance in a TERMINATED
state, whereas
methods such as reset()
and sudo reboot
only works on instances
that are currently running. Almost all instances can be restarted, as long as
the instance is in a TERMINATED
state.
Console
- Go to the VM Instances page in the Google Cloud Platform Console.
- Select the instances that you want to restart.
- At the top right-hand of the page, click the Start button to restart the instances.
gcloud
To reset your instance using gcloud compute
:
gcloud compute instances start example-instance
API
In the API, make a POST
request to the following URI, replacing the
project, zone, and instance name appropriately:
https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-f/instances/example-instance/start
To restart your instance using the client libraries, construct a request
to the instances().start
method:
def restartInstance(auth_http, gce_service):
request = gce_service.instances().start(project="myproject", zone="us-central1-a", instance="example-instance")
response = request.execute(auth_http)
print response
For more information on this method, see the instances().start
reference documentation.
Using other restart methods
You can also choose to reset your instance using the following methods as well:
sudo reboot
(Linux only) - Called from within the instance. Wipes the memory and re-initializes the instance with the original metadata, image, and persistent disks. It will not pick up any updated versions of the image, and the instance will retain the same ephemeral IP address. This is similar to restarting your computer.- Rebooting a Windows instance - You can reboot a Windows instance, similar to
sudo reboot
above, using the Start menu. In the Start menu, click on the arrow next to Log off and click Restart. gcloud compute instances delete
followed bygcloud compute instances create
- This is a completely destructive restart, and will initialize the instance with any information passed intogcloud compute instances create
. You can then select any new images or other resources you'd like to use. The restarted instance will probably have a different IP address. This method potentially swaps the physical machine hosting the instance.
What's next
- Learn how to stop an instance.
- Use the interactive serial console to troubleshoot your instance.
- Learn how to change the machine type.
- Delete an instance after you are done with it.