Last active
August 29, 2015 13:56
-
-
Save GeorgeDewar/8994881 to your computer and use it in GitHub Desktop.
Handy little script to shut down or boot up droplets on Digital Ocean - great for demonstrating redundant systems like Ceph, where similarly named nodes need to be killed and restarted during demonstrations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function usage { | |
echo "Shutdown and boot Digital Ocean droplets remotely, and simulate network disconnection" | |
echo | |
echo "Usage: $0 <kill/boot/killnet/resumenet> node1 [node2] [node3] [node...]" | |
exit 1 | |
} | |
# Get settings and node IDs from files | |
source ~/.digitalocean_api_creds | |
source node_info | |
# Print usage if there are less than two arguments (operation + node) | |
if [ "$#" -lt "2" ]; then | |
usage | |
fi | |
# Use the first parameter as the operation, then shift | |
op=$1 | |
shift 1 | |
for ARG in $* | |
do | |
node=$ARG | |
fqdn=$node.$domain | |
case "$op" in | |
kill) | |
echo "Telling $fqdn to shut down..." | |
ssh root@$fqdn poweroff | sed "s/^/$fqdn: /" | |
echo | |
;; | |
boot) | |
id=${!node} | |
echo "Telling Digital Ocean to boot $fqdn (droplet $id)..." | |
curl https://api.digitalocean.com/droplets/$id/power_on/?client_id=$client_id\&api_key=$api_key | |
echo | |
;; | |
killnet) | |
echo "Simulating network disconnection on $fqdn..." | |
ssh root@$fqdn /usr/bin/killnet kill | sed "s/^/$fqdn: /" | |
echo | |
;; | |
resumenet) | |
echo "Resuming network connection on $fqdn..." | |
ssh root@$fqdn /usr/bin/killnet resume | sed "s/^/$fqdn: /" | |
echo | |
;; | |
*) | |
usage | |
;; | |
esac | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It now integrates with nodekill.