EilonA
EilonA

Reputation: 571

How can I initiate a shutdown to an instance after certain time from when it started?

I have instances in GCP. I can schedule a time to start and stop using the scheduler. But, I don't want a specific time of the day, I want a specific time after instance was started.

For example - Stop the instance after 8 hours the instance is up and running.

Upvotes: 2

Views: 904

Answers (2)

Fabich
Fabich

Reputation: 3069

In the Google Console, if you go to your VM and click on "Edit" yout can set a time limit for the VM in the "Management" section

enter image description here

From the documentation of this preview feature:

Automatic termination lets you schedule a VM to be terminated (stopped or deleted) when it reaches a specific time limit (duration or time).

Upvotes: 1

rriovall
rriovall

Reputation: 486

You can add the contents of a startup script directly to a VM when you create the VM.

You can also pass a Linux startup script directly to an existing VM:

In your Cloud Console go to VM Instance page and click on the instance you want to pass the start up script

  1. Click Edit.

  2. Under Automation, specify the following:

 #! /bin/bash
shutdown -P +60

-P Instructs the system to shut down and then power down.

The time argument specifies when to perform the shutdown operation.

The time can be formatted in different ways:

First, it can be an absolute time in the format hh:mm, where hh is the hour (1 or 2 digits, from 0 to 23) and mm is the minute of the hour (in two digits).

Second, it can be in the format +m, where m is the number of minutes to wait.

Also, the word now is the same as specifying +0; it shuts the system down immediately.

Upvotes: 2

Related Questions