Saturday, October 22, 2011

Bukkit, restart script

The script we use to stop bukkit, tar up the world, render the overviewer map and restart bukkit again. The last part is rather silly as it involves a hacky way of getting a screen going that accepts "-X stuff". Reason is the screen has to have been connected to and detached again for it to work.

#!/bin/bash
# Heads up if anyones actually playing at the time of the restart.
# btw: `echo -ne '\015'` << sends "enter"
screen -S mine -X stuff "broadcast Going down in 5m!"`echo -ne '\015'`
sleep 200
screen -S mine -X stuff "save-all"`echo -ne '\015'`
sleep 30
screen -S mine -X stuff "broadcast Going down in 60s! Will be back in a while."`echo -ne '\015'`
sleep 30
screen -S mine -X stuff "broadcast Going down in 30s!"`echo -ne '\015'`
sleep 15
screen -S mine -X stuff "broadcast Going down in 15s!"`echo -ne '\015'`
sleep 15
screen -S mine -X stuff "broadcast Going down NOW!"`echo -ne '\015'`
sleep 1
screen -S mine -X stuff "stop"`echo -ne '\015'`
sleep 60

# Taring the world if anyone wants to download
tar -zcf /home/mine/viewer/world.tar.gz /home/mine/minecraft/world/

# Overviewer!
# Letting the server stay down while rendering. Not necessary.
/home/mine/overviewer/render.sh
sleep 30

# Getting a screen running that accepts -X stuff.
# There's a known bug (since 2008) where the screen session must be attached at least once to be able
# to receive commands through -X.
# First we start one screen with the express purpose of starting another screen and then close. 
# The second screen is then detached and we have our once-detached-screen accepting -X stuff. Yay!
screen -dmS tempmine bash -c "sleep 120"
sleep 1
screen -S tempmine -X screen screen -dR mine /home/mine/minecraft/server.sh
sleep 1
screen -S mine -X detach
sleep 15
screen -S mine -X stuff "broadcast Aaaaaaand we are back!"`echo -ne '\015'`