Skip to content

Instantly share code, notes, and snippets.

@svrc
Last active February 25, 2019 19:13
Show Gist options
  • Save svrc/1633b4ea3f72817df613774f41b498ab to your computer and use it in GitHub Desktop.
Save svrc/1633b4ea3f72817df613774f41b498ab to your computer and use it in GitHub Desktop.
Azure BOSH start/stop CLI
#!/bin/bash
# Azure Start/Stop CLI. Starts or Stops all BOSH-provisioned VMs in a resource group.
# Requires the "Azure 2.0 CLI", aka az ; requires it to be logged in to your azure account
trap "exit" INT
if [ -z "$2" ]; then
echo "Missing resource group"
echo "USAGE: azure-bosh.sh [start|stop] [resource group]"
exit 1
else
rg=$2
echo "using resource group $2"
fi
if [[ ($1 == "start") || ($1 == "stop") ]]; then
echo "Azure BOSH Start/Stop CLI"
else
echo "USAGE: azure-bosh.sh [start|stop] [resource group]"
exit 1
fi
echo "Gathering VM list"
VM_IDS=$(az vm list -g $rg --show-details --query "[?tags.\"user-agent\" == 'bosh'].name" -o tsv)
echo "VMs:"
echo "$VM_IDS"
if [[ $1 == "stop" ]]; then
for vm in $VM_IDS ; do echo "Stopping $vm" ; az vm stop -g $rg -n $vm --no-wait ; done
for vm in $VM_IDS ; do echo "Deallocating $vm" ; az vm deallocate -g $rg -n $vm --no-wait ; done
fi
if [[ $1 == "start" ]]; then
for vm in $VM_IDS ; do echo "Starting $vm"; az vm start -g $rg -n $vm --no-wait ; done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment