Advertisement
ionstorm66

minecraft script

Sep 27th, 2011
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.69 KB | None | 0 0
  1. #! /bin/sh
  2. WORLD=/opt/minecraft/world/
  3. WORLD_HDD=/opt/minecraft/world_hdd/
  4. RD_SIZE=1024M
  5. USER=minecraft
  6. RAM=4G
  7. BUKKIT=/opt/minecraft/craftbukkit.jar
  8. case "$1" in
  9.                 start)
  10.                 echo "Checking tmux session"
  11.                 if su $USER -c 'tmux ls | grep $USER' > /dev/null; then
  12.                         echo "tmux session detected killing server"
  13.                         su $USER -c 'tmux kill-session -t $USER'
  14.                 fi
  15.                 echo "Creating new session"
  16.                 su $USER -c 'tmux new-session -d -n bukkit -s $USER'
  17.                 su $USER -c 'tmux new-window -d -t $USER -n lsyncd'
  18.                 echo "Setting up RAMdisk"
  19.                 echo "   -Checking world folder"
  20.                 if [ "$(ls -A $WORLD)" ]; then
  21.                         echo "   -World folder not empty"
  22.                         echo "      -Resyncing backup world"
  23.                         su $USER -c "rsync -a $WORLD $WORLD_HDD"
  24.                         echo "      -Unmounting RAMdisk"
  25.                         umount $WORLD
  26.                         echo "      -Cleaning out world folder"
  27.                         rm -rf $WORLD
  28.                         echo "      -Remakeing world folder"
  29.                         su $USER -c "mkdir $WORLD"
  30.                 else
  31.                         echo "   -World folder empty, checking permissions"
  32.                         chown $USER:$USER $WORLD
  33.                 fi
  34.                 echo "   -Mounting RAMdisk"
  35.                 mount -t tmpfs -o size=$SIZE tmpfs $WORLD
  36.                 echo "   -Rsyncing world to RAMdisk"
  37.                 su $USER -c "rsync -a $WORLD_HDD $WORLD"
  38.                 echo "   -Fireing up lsyncd to live backup world"
  39.                 su $USER -c "tmux -q send -t $USER:lsyncd lsyncd Space -nodaemon Space -rsync Space $WORLD Space $WORLD_HDD Space C-m"
  40.                 echo "Starting Server"
  41.                 su $USER -c "tmux -q send -t $USER:bukkit java Space -Xmx $RAM Space -Xms $RAM Space -jar Space $BUKKIT Space C-m"
  42.                 echo "   -Waiting for startup"
  43.                 wait 30
  44.                 echo "   -Checking Server Status"
  45.                 $0 status
  46.                 ;;
  47.         stop)
  48.                 echo "Shutting down server"
  49.                 su $USER -c "tmux -q send -t $USER:bukkit say Space Server Space is Space going Space offline. C-m"
  50.                 echo "   -Disabling saving"
  51.                 su $USER -c "tmux -q send -t $USER:bukkit save-off C-m"
  52.                 echo "   -Saving world"
  53.                 su $USER -c "tmux -q send -t $USER:bukkit save-all C-m"
  54.                 echo "   -Stopping server"
  55.                 su $USER -c "tmux -q send -t $USER:bukkit stop C-m"
  56.                 echo "Stoping lsyncd"
  57.                 su $USER -c "tmux -q send -t $USER:lsyncd C-c"
  58.                 echo "Syncing backup"
  59.                 su $USER -c "rsync -a $WORLD $WORLD_HDD"
  60.         echo "Clearing out tmux sessions"
  61.         su $USER -c "tmux kill-session - $USER"
  62.                 ;;
  63.         restart)
  64.                 $0 stop
  65.                 $0 start
  66.                 ;;
  67.         reload)
  68.                 echo -n "Reloading Bukkit "
  69.                 su $USER -c "tmux -q send -t $USER:bukkit reload C-m"
  70.                 ;;
  71.         status)
  72.                 echo -n "Checking Server Status"
  73.                 if [ "ps ax | grep -v grep | grep -v tmux | grep $BUKKIT" > /dev/null ]; then
  74.                         PID=`ps ax | grep -v grep | grep -v sh | grep -v -i 'tmux' | grep "$BUKKIT"`
  75.                         top -n 1 -p ${PID:0:5} | grep ${PID:0:5}
  76.         fi
  77.         ;;
  78.     *)
  79.         ## If no parameters are given, print which are avaiable.
  80.         echo "Usage: $0 {start|stop|status|restart|reload|update}"
  81.         exit 1
  82.         ;;
  83. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement