azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

[VM] --auto-shutdown command

Open dovry opened this issue 8 years ago • 9 comments

Is your feature request related to a problem? Please describe. Seems that the CLI has most of the features that the portal supports, except one of the marketable features of cloud computing. Auto shutdown saves you money for when you're not using a mission critical VM or labbing at home.

Describe the solution you'd like if no time-zone is specified, defaults to UTC date format defaults to AM/PM, unless "24" is specified if no time is specified, defaults to 07:00:00 pm

--auto-shutdown "timezone" "format" "hh:mm:ss" example commands: #shuts down VM at 19:00:00 UTC+1 --auto-shutdown "UTC+01:00" "24" "19:00:00" #shuts down at 6 pm UTC --auto-shutdown "06:00:00" #shuts down at 3 in the morning UTC --auto-shutdown "24" "03:00:00"

Describe alternatives you've considered I've looked at ways to do this and what's come up are hacky solutions such as running cronjobs on each individual vm, or cronjobs for running .sh scripts on my pc to remotely shut down the machines. I am also aware of of 'az vm stop', but again that requires manual input or cronjobs on the user's end.

dovry avatar Sep 06 '18 08:09 dovry

@yugangw-msft do you know if this is supported by the sdk? I have a feeling it isn't.

williexu avatar Sep 07 '18 22:09 williexu

This is a DevTest Lab feature. I enabled it through the portal and exported the RG.

 {
      "type": "microsoft.devtestlab/schedules",
      "name": "[parameters('schedules_shutdown_computevm_vm1_name')]",
      "apiVersion": "2016-05-15",
      "location": "westus",
      "scale": null,
      "properties": {
        "status": "Enabled",
        "taskType": "ComputeVmShutdownTask",
        "dailyRecurrence": {
          "time": "1900"
        },
        "timeZoneId": "Pacific Standard Time",
        "notificationSettings": {
          "status": "Disabled",
          "timeInMinutes": 30
        },
        "targetResourceId": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachines_vm1_name'))]",
        "provisioningState": "Succeeded",
        "uniqueIdentifier": "feb37ca6-81d9-4348-b70d-ffbd3e5bb218"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachines_vm1_name'))]"
      ]

tjprescott avatar Oct 01 '18 20:10 tjprescott

+1, with details -- I am able to configure auto-shutdown in the Portal for a regular VM (in a non-DevTest Lab subscription/configuration). But I don't see this reflected in the CLI or exported template?

It would be extremely valuable (though maybe less to Azure :wink:) for me to be able to have a script that:

az vm start -g g1 -n vm1
az vm configure \
  --feature auto-shutdown \
    --date "$(TZ=UTC date --date="2 hours") \
    --alert-email "[email protected]" \
  --resource-group g1 \
  --name vm1

It would be fun to write scripts around this, too. I could have a long-running script on my laptop that watches for when the shutdown time is about to be hit, it could send me a desktop notification with a button that would extend out the shutdown time another hour.

colemickens avatar Jul 12 '19 07:07 colemickens

(also, if I should file a different bug for general compute, since this is tagged DevTestLab, let me know, thanks)

colemickens avatar Jul 12 '19 07:07 colemickens

I would like to see this implemented as well. Very useful.

mreid-contrast avatar Sep 26 '19 00:09 mreid-contrast

There is no reason why it shouldn't be available out-of-the-box in the Azure CLI.

Are we getting this feature or not?

epomatti avatar Mar 22 '20 15:03 epomatti

+1 to this feature

fgbaezp avatar Apr 10 '20 04:04 fgbaezp

Is your feature request related to a problem? Please describe. Seems that the CLI has most of the features that the portal supports, except one of the marketable features of cloud computing. Auto shutdown saves you money for when you're not using a mission critical VM or labbing at home.

Describe the solution you'd like if no time-zone is specified, defaults to UTC date format defaults to AM/PM, unless "24" is specified if no time is specified, defaults to 07:00:00 pm

--auto-shutdown "timezone" "format" "hh:mm:ss" example commands: #shuts down VM at 19:00:00 UTC+1 --auto-shutdown "UTC+01:00" "24" "19:00:00" #shuts down at 6 pm UTC --auto-shutdown "06:00:00" #shuts down at 3 in the morning UTC --auto-shutdown "24" "03:00:00"

Describe alternatives you've considered I've looked at ways to do this and what's come up are hacky solutions such as running cronjobs on each individual vm, or cronjobs for running .sh scripts on my pc to remotely shut down the machines. I am also aware of of 'az vm stop', but again that requires manual input or cronjobs on the user's end.

Can you share a sample cronjob / script, so that I can replicate? It would be helpful I'm new to this realm.

jerinthomas1404 avatar Nov 03 '20 11:11 jerinthomas1404

Please check https://github.com/Azure/azure-cli/pull/13199. This feature has already been implemented.

a0x1ab avatar Aug 21 '25 05:08 a0x1ab