question

SirWin-2495 avatar image
SirWin-2495 asked ·

Automatically run custom scripts when starting the VM ?

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-extension
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ManuPhilip avatar image
ManuPhilip answered ·

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

1 comment Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Can you send me the demo script?

0 Votes 0 · ·
SirWin-2495 avatar image
SirWin-2495 answered ·

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"}'

Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ManuPhilip avatar image
ManuPhilip answered ·

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

3 comments Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I am using ubuntu, does powershell.exe work on ubuntu?

0 Votes 0 · ·

Hi,
Ubuntu runs only the script script.sh saved in your storage account> 'sudo sysctl -w vm.nr_hugepages=512"'. That means the script.sh is file contains the line and is being initiated by PowerShell

Thanks,
Manu

0 Votes 0 · ·

Hi,

Any update on this post?

If the suggested response helped you resolve your issue, do click on "Mark as Answer" and "Up-Vote" for the answer that helped you for benefit of the community.

Thanks,
Manu

0 Votes 0 · ·