none
How do i schedule a reboot of a linux vm? RRS feed

  • Question

  • Hi!

    How do i schedule a reboot (every night) for a linux vm?

    I saw that an automatic shutdown is already in the gui, but how do i schedule a reboot?

    Thanks a lot! 

    Otto

    Friday, September 13, 2019 3:36 PM

All replies

  • Hi, 

    You can write s custom script to automate the restart VM with the REST API. 

    Sample:

    POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/restart?api-version=2019-03-01

    Reference: https://docs.microsoft.com/en-us/rest/api/compute/virtualmachines/restart

    Or you can use the PowerShell command to restart the VM with the below command:

    Restart-AzVM
           [-ResourceGroupName] <String>
           [-Name] <String>
           [-AsJob]
           [-NoWait]
           [-DefaultProfile <IAzureContextContainer>]
           [-WhatIf]
           [-Confirm]
           [<CommonParameters>]

    All you need to do is to run this command in a loop with a Sleep command:

    start-sleep -Seconds XX

    Let me know if you have any further questions. 

    Regards, 

    Msrini


    Friday, September 13, 2019 3:48 PM
    Moderator
  • Any update on this issue?

    If the above helped please remember to "Up-vote" and "Mark as Answer" so others in the community can benefit

    Friday, September 20, 2019 11:40 PM
    Moderator
  • Hello,

    Any update on this issue?

    If the suggested answer helped you solve your issue, please remember to "Mark as Answer" and "Up-Vote"so others in the community can benefit from it.

    Thanks.
    Tuesday, September 24, 2019 5:53 AM
    Moderator