Use a Startup Script for Azure Nodes

You can configure a startup script that runs automatically on a set of Azure nodes when they are started (provisioned). Using a startup script, you can ensure that a group of nodes are configured properly to run specific jobs. Additionally, the nodes are restored to a known state if they become unavailable because of a service interruption and the role instances need to be provisioned in Azure again. For example, using a startup script, you can install applications or drivers, configure a shared folder, or open firewall ports for specific applications. You can also use a startup script to configure subsets of nodes differently within the set of Azure nodes that are deployed using a particular node template.

In this topic:

Note

  • Azure startup scripts are supported starting with HPC Pack 2008 R2 with Service Pack 2.
  • If a startup script takes longer than 15 minutes to complete, the Azure Fabric Controller might cause the provisioning of a role instance to fail.

General steps to configure and use a startup script

The following are the general steps for configuring and using a startup script for your Azure nodes:

  1. Create a configuration script (for example, startup.bat) that uses environment variables to differentiate nodes and to set different configurations. For more information, see the remaining sections in this topic.

  2. Use the hpcpack command to package the script and upload it to the Azure storage account that is used for deploying the Azure nodes.

    Important

    Do not specify the /relativePath parameter when packaging and uploading the startup script. The startup script should only run from the root directory of the Azure nodes.

  3. Create or edit an Azure node template to specify the startup script.

  4. Start (provision) the Azure nodes.

    The startup script is automatically deployed to the Azure nodes and runs on the nodes. If a problem occurs when the script runs, you can review the error logs. For more information, see Troubleshoot Deployments of Azure Nodes with Microsoft HPC Pack.

Script names

You must ensure conformity between the name of the package that you upload to Azure and the name of the script that runs (and that is specified in the node template). Only the naming conventions in the following table are allowed:

Script name Package name
file.extension (example: startup.bat) file.extension.zip (example: startup.bat.zip)

-OR-

file.zip (example: startup.zip)

Environment variables

You can use the environment variables in the following table, which are set automatically on the Azure nodes, to help configure your startup script:

Environment variable Description
HPC_NODE_NAME The name of the Azure node that is automatically configured by Microsoft HPC Pack – for example, AZURECN-0014.
HPC_NODE_GROUPS A comma-delimited list of node groups that the node belongs to. Allows the behavior of a script to be specialized for different subsets of the nodes. Note: HPC_NODE_GROUPS is set only when the Azure node is first started. The variable is not dynamically updated if the variable is updated and the node is then provisioned again.

Example

The following example is a batch file that configures a firewall rule on a subset of nodes that are identified by the node group Port31337 Server Group. You can adapt this pattern to create startup scripts that perform other tasks.

@echo off  
echo %HPC_NODE_GROUPS% | findstr /C: "Port31337 Server Group"  
if %errorlevel% == 0 (  
echo Creating firewall exception  
netsh advfirewall firewall add rule name="MyRule" dir=in protocol=tcp localport=31337 action=allow enable=yes  
)  
  

Log files

If a problem occurs when a startup script runs, review the log files for the script. The logs for the startup scripts are listed in the following table. The log files are in the %CCP_HOME% folder on each Azure worker node.

Log file Description
HpcStartupCommand.log Exit code and output stream
HpcStartupCommand.err Error stream

See Also

Configuring an Azure Node Template for Microsoft HPC Pack