-
-
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.
This file contains hidden or 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 | |
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