Skip to content

Instantly share code, notes, and snippets.

@dequis dequis/manage.sh
Last active Aug 29, 2015

Embed
What would you like to do?
enterprise twitpic management system
# enterprise twitpic management system
#
# requires tugboat for digital ocean management:
# gem install tugboat
# tugboat authorize
#
# usage:
# sh manage $droplet command1 command2 command3
#
# commands:
# new create + check + install + start + info
# create creates droplet
# destroy destroys droplet
# install initial setup
# check check if banned, abort if so
# pull git pull
# start starts pipeline in tmux
# stop sends stop signal to pipeline
# attach attach to tmux in droplet
# kill kills pipeline by shutting tmux down
# info shows connection info for droplet
#
DO_IMAGE=5142677 # ubuntu 14.04 32bit
DO_SSH_KEY=CHANGEME # get this with 'tugboat keys'
DO_SIZE=66 # 512mb
DO_REGION=8 # new york 3
CONCURRENT=20 # for pipeline
NICKNAME=CHANGEME # your name here
create() {
tugboat create $droplet -s $DO_SIZE -i $DO_IMAGE -r $DO_REGION -k $DO_SSH_KEY
tugboat wait $droplet
get_ip
echo Waiting for ssh...
while ! ssh -o ConnectTimeout=5 root@$address true; do
sleep 5;
done
echo Done
}
destroy() {
tugboat destroy $droplet
}
get_ip() {
if [ $address ]; then
return
fi
address=$(tugboat info $droplet | grep IP | awk '{print $2}')
if [ -z $address ]; then
echo Droplet not found
exit 1
fi
echo IP: $address
}
check() {
get_ip
if [ $(ssh root@$address curl -s -o /dev/null -w "%{http_code}" twitpic.com) = 403 ]; then
echo Banned
exit 1
else
echo Still alive
fi
}
install() {
get_ip
echo Installing
ssh root@$address "
apt-get update -qq
apt-get install -qy git-core lua5.1 liblua5.1-0 python-dev python-pip
pip install seesaw
wget -q https://launchpad.net/~archiveteam/+archive/ubuntu/wget-lua/+files/wget-lua_1.14.lua.20130523-9a5c-1ppa1%7Eraring1_i386.deb -O wget-lua.deb
dpkg -i wget-lua.deb
echo set -g set-remain-on-exit on > .tmux.conf
git clone https://github.com/ArchiveTeam/twitpic-grab.git
cd twitpic-grab
sed -i '/sleep 10/ s/10/1/' twitpic.lua
"
echo Install done
}
pull() {
get_ip
echo Pulling
ssh root@$address 'cd twitpic-grab; git pull'
echo Done
}
start_pipeline() {
get_ip
echo Starting pipeline
ssh root@$address "
cd twitpic-grab
if tmux list-windows 2>/dev/null | grep -v dead &>/dev/null; then
echo Already running
else
echo Starting new session
tmux new-session -d 'run-pipeline pipeline.py --concurrent $CONCURRENT $NICKNAME'
fi
"
echo Done
}
stop_pipeline() {
get_ip
ssh root@$address touch twitpic-grab/STOP
echo Sent stop signal
}
info() {
get_ip
echo Attach to tmux with: $0 $droplet attach
echo Or view in browser: http://$address:8001/
}
attach() {
get_ip
ssh -t root@$address tmux a
}
droplet=$1
shift
if [ -z $droplet ]; then
echo Droplet name required
exit 1
fi
for arg in "$@" ; do
case "$arg" in
check)
check
shift
;;
install)
install
shift
;;
pull)
pull
shift
;;
start)
start_pipeline
shift
;;
stop)
stop_pipeline
shift
;;
kill)
kill_pipeline
shift
;;
destroy)
destroy
shift
;;
info)
info
shift
;;
attach)
attach
shift
;;
create)
create
shift
;;
new)
create
check
install
start_pipeline
info
shift
;;
*)
echo Unknown parameter
exit 1
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.