Running Low-Priority VMs (LPVMs) in Azure reduces the infrastructure costs by 80%. However, LPVMs might get terminated by Azure within a very short notice of 0 to 30 seconds. With Elastigroup, there’s a way to run workloads in a reliable, and efficient manner, maintaining High-Availability while reducing 80% of the VM costs.

DevOps and IT Engineers, want to have control over a clean and graceful shutdown process when a VM is being terminated. Elastigroup enables two important features for LPVMs:

  1. Send a notification before termination (Email, or HTTP endpoint)
  2. Execute a pre-defined Shutdown script on the VM before it gets terminated

Shutdown scripts is basically a shell (bash) or Powershell script that will be executed on the VM before termination happens, the output of the shutdown script is being sent to Spotinst Elastigroup SaaS and is available for debugging & logging purposes later on.


Adding a Shutdown Script To Spotinst Elastigroup



  • Spotinst Agent

You can install the agent manually, Or, just add it as part of your instance startup script.

#!/usr/bin/env bash
echo "curl -fsSL https://s3.amazonaws.com/spotinst-public/services/agent/azure-elastigroup-agent-init.sh | \
bash" |  at now + 5 minute
  • SPOTINST_ACCOUNT_ID can be found here.
  • SPOTINST_TOEKN can be fetched from here.


  • Step 1: Go into Spotinst console, and Edit Configuration for your Elastigroup
  • Step 2: Navigate to Compute tab, and open the Additional Configuration
  • Step 3: Under shutdown script, add your desired shell script

For example:

#enter shutdown script here
#!/usr/bin/env bash 
"Goodbye old instance"

  • Step 4: Click on next -> Update, and you’re done!


Important Notes

  • Spotinst agent is using pip (Python 2.7 Package Manager)
  • Shutdown scripts must start with the #! characters and the path to the interpreter you want to read the script (e.g. /bin/bash)
  • Shutdown scripts are being executed as the root user, sudo is not required in the script. Remember that any files you create will be owned by root; for non-root permissions to files – please modify permissions accordingly.
  • Shutdown script doesn’t run interactively, you cannot include commands that require user feedback (such as rm without the -f flag)
  • It is recommended to define at least 120 seconds as the Draining Timeout under Elastigroup -> Edit -> General -> Advanced