Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /bin/sh
- WORLD=/opt/minecraft/world/
- WORLD_HDD=/opt/minecraft/world_hdd/
- RD_SIZE=1024M
- USER=minecraft
- RAM=4G
- BUKKIT=/opt/minecraft/craftbukkit.jar
- case "$1" in
- start)
- echo "Checking tmux session"
- if su $USER -c 'tmux ls | grep $USER' > /dev/null; then
- echo "tmux session detected killing server"
- su $USER -c 'tmux kill-session -t $USER'
- fi
- echo "Creating new session"
- su $USER -c 'tmux new-session -d -n bukkit -s $USER'
- su $USER -c 'tmux new-window -d -t $USER -n lsyncd'
- echo "Setting up RAMdisk"
- echo " -Checking world folder"
- if [ "$(ls -A $WORLD)" ]; then
- echo " -World folder not empty"
- echo " -Resyncing backup world"
- su $USER -c "rsync -a $WORLD $WORLD_HDD"
- echo " -Unmounting RAMdisk"
- umount $WORLD
- echo " -Cleaning out world folder"
- rm -rf $WORLD
- echo " -Remakeing world folder"
- su $USER -c "mkdir $WORLD"
- else
- echo " -World folder empty, checking permissions"
- chown $USER:$USER $WORLD
- fi
- echo " -Mounting RAMdisk"
- mount -t tmpfs -o size=$SIZE tmpfs $WORLD
- echo " -Rsyncing world to RAMdisk"
- su $USER -c "rsync -a $WORLD_HDD $WORLD"
- echo " -Fireing up lsyncd to live backup world"
- su $USER -c "tmux -q send -t $USER:lsyncd lsyncd Space -nodaemon Space -rsync Space $WORLD Space $WORLD_HDD Space C-m"
- echo "Starting Server"
- su $USER -c "tmux -q send -t $USER:bukkit java Space -Xmx $RAM Space -Xms $RAM Space -jar Space $BUKKIT Space C-m"
- echo " -Waiting for startup"
- wait 30
- echo " -Checking Server Status"
- $0 status
- ;;
- stop)
- echo "Shutting down server"
- su $USER -c "tmux -q send -t $USER:bukkit say Space Server Space is Space going Space offline. C-m"
- echo " -Disabling saving"
- su $USER -c "tmux -q send -t $USER:bukkit save-off C-m"
- echo " -Saving world"
- su $USER -c "tmux -q send -t $USER:bukkit save-all C-m"
- echo " -Stopping server"
- su $USER -c "tmux -q send -t $USER:bukkit stop C-m"
- echo "Stoping lsyncd"
- su $USER -c "tmux -q send -t $USER:lsyncd C-c"
- echo "Syncing backup"
- su $USER -c "rsync -a $WORLD $WORLD_HDD"
- echo "Clearing out tmux sessions"
- su $USER -c "tmux kill-session - $USER"
- ;;
- restart)
- $0 stop
- $0 start
- ;;
- reload)
- echo -n "Reloading Bukkit "
- su $USER -c "tmux -q send -t $USER:bukkit reload C-m"
- ;;
- status)
- echo -n "Checking Server Status"
- if [ "ps ax | grep -v grep | grep -v tmux | grep $BUKKIT" > /dev/null ]; then
- PID=`ps ax | grep -v grep | grep -v sh | grep -v -i 'tmux' | grep "$BUKKIT"`
- top -n 1 -p ${PID:0:5} | grep ${PID:0:5}
- fi
- ;;
- *)
- ## If no parameters are given, print which are avaiable.
- echo "Usage: $0 {start|stop|status|restart|reload|update}"
- exit 1
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement