Toby 1 Kenobi
Toby 1 Kenobi

Reputation: 5037

Automatically stop and start a Google Compute Engine instance

I'm using a Google Compute Engine instance for file synchronization. In order to save money I want the instance to be stopped overnight in my time zone. Is there any way to make the instance stop and start at particular times?

I know that I can send the stop and start commands to it using an HTTP request, but how would I send such a request at the right times if my own computers are not always 'on' at those times?

Upvotes: 2

Views: 4170

Answers (2)

Mohamed Amine
Mohamed Amine

Reputation: 2304

If you can send HTTP requests to turn on and turn off an instance, I would advise to use a standalone Google App Script from your Google Drive, that you can configure be executed every morning and every night through script triggers.

From this link :

To manually create an installable trigger through a dialog in the script editor, follow these steps:

  1. From the script editor, choose Resources > Current project's triggers.
  2. Click the link that says: No triggers set up. Click here to add one now.
  3. Under Run, select the name of function you want to trigger.
  4. Under Events, select either Time-driven or the Google App that the script is bound to (for example, From spreadsheet).
  5. Select and configure the type of trigger you want to create (for example, an Hour timer that runs Every hour or an On open trigger).
  6. Optionally, click Notifications to configure how and when you will be contacted by email if your triggered function fails.
  7. Click Save.

Upvotes: 1

Grzenio
Grzenio

Reputation: 36639

This is not properly supported yet. You need to manually call start/stop commands (using HTTP, gcloud, etc.) from your own scheduler. You could take a look at google app engine, I think it should be possible to implement this kind of functionality there (if you don't have a spare machine to run cron jobs on).

Upvotes: 2

Related Questions