Skip to content

Instantly share code, notes, and snippets.

@chenchun
Forked from hex108/vps
Created February 28, 2020 04:46
Show Gist options
  • Save chenchun/83957720fb8ee603494ce204a35fd1e7 to your computer and use it in GitHub Desktop.
Save chenchun/83957720fb8ee603494ce204a35fd1e7 to your computer and use it in GitHub Desktop.
Manage(start/stop/status) vps on DigitalOcean. You could install shadowsocks automatically when creating a new vps.
#!/bin/bash
set -e
set -u
#set -x
SSH_KEY="05:8b:8f:f5:09:35:ae:61:a9:3b:21:ea:1c:36:bf:0c"
USER_DATA_FILE="$(dirname $0)/vps.userdata"
### sub functions
start() {
current_droplets_num=$(doctl compute droplet list | wc -l)
if [ $current_droplets_num -gt 1 ]; then
echo "You have already had a droplet now!!!"
doctl compute droplet list
exit 0
fi
echo "=> Create droplet"
doctl compute droplet create vps --size 512mb --image ubuntu-16-10-x64 --region sgp1 --ssh-keys $SSH_KEY --user-data-file $USER_DATA_FILE
}
stop() {
droplets=$(doctl compute droplet list | grep -v '^ID' | awk '{print $1}')
for droplet in "$droplets"; do
echo "=> Delete droplet $droplet"
doctl compute droplet delete -f $droplet
done
}
status() {
doctl compute droplet list
}
usage() {
echo "Usage: $0 start|stop|status"
}
### main start
if [ $# != 1 ]; then
usage
exit 0
fi
ACTION=$1
case "$ACTION" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
*)
usage
exit 0
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment