Running a Bash command after scaling an Azure VM Scale Set

Barak Pahima 60 Reputation points
2023-08-06T12:52:59.1733333+00:00

Hello,

I am working with an Azure VM Scale Set running Ubuntu OS and have written Java code to scale it up or down. However, I am struggling with post-deployment scripts. I need each new VM created in the set to run a Bash script when it starts, and the script should be unique for each VM, with only one variable changing.

What is the solution for running these scripts after a new VM is created and running? I have explored the possibility of using Custom Script, but I have not been able to find any API in the Java SDK to accomplish this.

Thank you,

Barak.

Azure Virtual Machine Scale Sets
Azure Virtual Machine Scale Sets
Azure compute resources that are used to create and manage groups of heterogeneous load-balanced virtual machines.
448 questions
{count} votes

Accepted answer
  1. kobulloc-MSFT 26,801 Reputation points Microsoft Employee Moderator
    2023-08-11T19:05:03.4466667+00:00

    Hello, @Barak Pahima !

    How do I run a script after a VM deployment using the Java SDK?

    It looks like you're specifically looking for something that you can use with a Java SDK deployment workflow. You can use custom data and there's a detailed post that goes through what this looks like.

    Looking at the Azure Java SDK examples, this is what caught my attention:

    // Use a VM extension to install Apache Web servers
                            .defineNewExtension("CustomScriptForLinux")
                                .withPublisher("Microsoft.OSTCExtensions")
                                .withType("CustomScriptForLinux")
                                .withVersion("1.4")
                                .withMinorVersionAutoUpgrade()
                                .withPublicSetting("fileUris", fileUris)
                                .withPublicSetting("commandToExecute", installCommand)
                                .attach()
    

    Let me know in the comments if this is useful or if you need additional guidance.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Sedat SALMAN 14,180 Reputation points MVP
    2023-08-06T14:11:37.5466667+00:00

    You can use Azure Custom Script Extension for post-deployment configuration on Linux Machines.

    You can check the following link.

    https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-linux

    Azure Instance Metadata Service can be another option to configure virtual machines

    https://learn.microsoft.com/en-us/azure/virtual-machines/instance-metadata-service?tabs=windows

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.