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:
- Send a notification before termination (Email, or HTTP endpoint)
- 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 | \ SPOTINST_ACCOUNT_ID="" \ SPOTINST_TOKEN="" \ bash" | at now + 5 minute
- 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
#enter shutdown script here #!/usr/bin/env bash "Goodbye old instance"
- Step 4: Click on next -> Update, and you’re done!
- 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.
- Shutdown scripts are being executed as the root user,
sudois 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
- It is recommended to define at least 120 seconds as the Draining Timeout under Elastigroup -> Edit -> General -> Advanced