Automatically run custom scripts when starting the VM ?

SirWin 1 Reputation point
2020-06-19T17:51:22.983+00:00

I use the following command to run when creating the VM. But when the VM reboots, it no longer executes.
How to set the script to run each time the VM is started.

az vmss extension set \
--vmss-name VM1 \
--resource-group myResourceGroup \
--publisher http://Microsoft.Azure.Extensions \
--version 2.0 \
--name CustomScript \
--settings '{"commandToExecute":"sudo sysctl -w vm.nr_hugepages=512"}'

Thanks!

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,569 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Manu Philip 17,351 Reputation points MVP
    2020-06-19T19:37:51.273+00:00

    Hello,

    You need to upload your scripts inside a storage account or Github, then get the URL. Modify the procedure so that it access the location and get the script when the VM reboots

    Please mark as "Accept the answer" if the above steps helps you. Others with similar issues can also follow the solution as per your suggestion

    Regards,

    Manu


  2. SirWin 1 Reputation point
    2020-06-20T12:59:16.387+00:00

    I tried like this, but it doesn't seem to work.
    --settings '{"fileUris": ["https://raw.githubusercontent.com/sirwin11/ABC/master/script.sh"],"commandToExecute": "./script.sh"}'

    0 comments No comments

  3. Manu Philip 17,351 Reputation points MVP
    2020-06-20T16:03:49.407+00:00

    The usage is bit tricky. Ty as following. Save the script inside your storage account share

    --settings '{"fileUris": ["http://pw1.file.core.windows.net/pw2/script.sh"],
    "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File script.sh"}'

    Thanks,
    Manu