9

I am playing with Google Compute Engine with debian as the source image. I understand that I will be charged by the hour for as long as the instance is running, regardless whether i ssh in or not. The shutdown -h command apparently put the instance in terminated mode, and i would have to create the instance again for next time.

My question is, how do i just shut the VM down without terminating it? is that an option?

Google Say that : https://developers.google.com/compute/docs/troubleshooting If you shut down your instance using sudo shutdown or sudo poweroff, it is the equivalent of terminating it. There is no way to "freeze" an instance and restart it at a later time. You must recreate your instance if you choose to shut it down. When an instance is shut down from inside, it goes into the TERMINATED state but will still appear in the API (such as when you list instances). To remove it from the list, you must delete the instance explicitly. However, uptime for a TERMINATED instance is not billed.

user2773013
  • 3,102
  • 8
  • 38
  • 58
  • 1
    You can delete an instance, and keep the persisting disk. When you create a new instance just use the persisting disk again [1]: http://stackoverflow.com/questions/16608594/how-to-automatically-exit-stop-the-running-instance – re Paul Dec 31 '13 at 16:21
  • 2
    The currently-accepted answer is no longer correct; see [my answer](http://stackoverflow.com/a/28033482/3618671) for the latest status. – Misha Brukman Jun 07 '15 at 00:17

6 Answers6

16

I know this thread is a bit old, but the Shutdown/Start feature has now been introduced in the Developers console and command line, so no need to create snapshots anymore.

Documentation is available here

Marius I
  • 1,461
  • 12
  • 13
10

You can stop an instance via any of the following methods:

See the docs for more information, including what effect this has on resources, and what actions you can take on a stopped instance.

On a related note, see also the docs for restarting a stopped instance.

Misha Brukman
  • 12,938
  • 4
  • 61
  • 78
6

What you can do is to save all your data to the hard disk, then shut down, and next time create an instance with the same disk.

Shutting down from the web console via:

Compute Engine > VM INSTANCES > Click on engine name > Delete

there is a checkbox saying:

Also delete boot disk "instance0"

If you leave it unchecked, next time you create another instance for the project you can select:

Boot source > Existing persistent disk

And then:

Source disk > Name of project

And your old disk will be intact.

Deleting the instance this way removed it from the instance list for me, while doing a poweroff didn't remove it immediately.

Beware: persistent storage used for the disks has a (relatively small) monthly cost. I was charged a few cents for some unused data without any email warning.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
5

My question is, how do i just shut the VM down without terminating it? is that an option?

Unfortunately, you can't. AWS EC2 is the exception when it comes to preserving instances on shutdown. Not even OpenStack providers support that out of the box. The workaround is to create an image based on the snapshot you want and then create a new instance based on that image.

rdodev
  • 3,164
  • 3
  • 26
  • 34
  • 3
    Or, just don't delete the boot disk when deleting the instance. You can then make a new instance and connect it to the same persistent disk, no snapshots involved. – fotinakis Jul 29 '14 at 22:57
  • 2
    This answer is obsolete now, see Marius' answer. – papirrin Apr 28 '16 at 19:59
  • I'd like to highlight about AWS EC2 is the exception. Agree but only if use [VPC/EBS](http://stackoverflow.com/a/38235022/4058484). – eQ19 Jul 14 '16 at 12:38
0

In addition to rdodev's point, alternatively you can also detach the persistent disk. When starting another instance, you can instrument previous configuration through a start-up script. Not quite the same, but alternative.

vgt
  • 217
  • 1
  • 4
0

The closest solution is to delete the instance while not deleting the persistent disk. When you need to restart the instance, just a create a new one with that disk. You can choose an instance with the same characteristics or different characteristics. It doesn't matter.

David Gageot
  • 2,496
  • 1
  • 22
  • 13