Simply bash scripts

Simply bash scripts

Required configurations

If you using Linux for bukkit, you can use many helpful scripts from forum or use simply scripts and few suggestions from this solution.

You need install in your Linux distribution screen for running bukkit console in virtual screen, vim or other editor, if you connecting to your server from Windows using Putty you should install vim it's easier to insert code, you need root rights to do that.

  • Debian/Ubuntu
    • apt-get install -y screen vim
      
  • Fedora/openSuse
    • yum install -y screen vim
      

Installing

  • Installing
    • Create blank file in your server named MC just like below
      • vim /usr/bin/MC
    • You will see vim interface.
    • Now, copy script from below and now in vim interface click key i now you can insert code, in putty it's simple just click right mouse button and weight a moment.
      • You can move in your document use arrow, check the first line in your document if it is different than in the example, press ESC and pres key u. Now repeat step above
    • Now finde line with MC_dir and insert yor bukkit main directory, if you want change screen session name you can do it changen value MC_screen
    • If all is correct press ESC and insert :x and accept Enter
    • Now use command chmod +x /usr/bin/MC
    • Finally you can use command MC to start, stop, connect to screen session or keep alive tour server
      • Caution!!!! If you want leave screen session you should use key combination CTRL + A + D or close terminal window.
      • Caution!!!! If you use another script you should read carefully your developer instructions, if thay dont tall that you can close termial window and server will be keep alive you can't do that.
  • Configuration
    • MC_dir=/home/minecraft/.minecraft_server < your bukkit main directory
    • MC_screen='MC'* < bukkit screen session name

MC - sample script

#!/bin/bash
MC_dir=/home/minecraft/.minecraft_server
cd $MC_dir
MC_screen='MC'

_stan() {
      pid=`cat /home/minecraft/.minecraft_server/server.pid`
      if [ `ps auxw | grep java | grep $pid | awk '{print $2}'` > 0 ]
      then
        return 1;
      else
        return 0;
      fi
}

if [ $# = 1 ] ; then
      for choice in $1 ; do
         case "$choice" in
          start)
             if [ _stan > 0 ] ; then
              echo -e "\n  Minecraft Server is already running!!\n"
             else
              echo -e "\n  Minecraft Server is started!!\n"
              screen -dmS $MC_screen java -server -Xmx3072M -jar craftbukkit.jar nogui -d yyyy-MM-dd HH:mm:ss
             fi
             exit 0;;
          stop)
              if [ _stan > 0 ] ; then
              echo -e "\n   Minecraft Server is prepared to stop!!\n"; screen -S $MC_screen -X stuff "say The server will stop in 10 seconds!!
"; sleep 1
                for i in 9 8 7 6 5 4 3 2 1
                do
                        screen -S $MC_screen -X stuff "say $i!!!
"
                    echo -n "."
                sleep 1
                done
              echo -e "\n   Sending a stop signal to the server!!\n"
              screen -S $MC_screen -X stuff "say The server is just turned off!!
stop
"
                   while [ ] ; do
                    echo -n "."
                    sleep 1
                    if [ _stan > 0 ] ; then
                     return 0;
                    fi
                   done
                echo -e "[\e[0;32mOK\e[0m]\n   Minecraft Server is disabled!!\n"
             else
                echo -e "\n   Minecraft Server isn't running!!\n"
             fi
             exit 0;;
          restart)
                   MC stop
                   sleep 3
                   MC start
          exit 0 ;;
          view)
                   echo -e "\n   Preparing to connect to Minecraft Server!!\n" ; screen -rx $MC_screen
          exit 0 ;;
          live)
          if [ _stan > 0 ] ; then
                echo -e "\n   Server is working!!\n"
                else
                echo -e "\n   Minecraft Server isn't running!!\n"
                MC start
          fi
          exit 0 ;;
          help)
             echo -e "Autor Marek Opłotny"
             echo -e "Kontakt oplotny.marek@gmail.com"
             echo -e "Kontakt a520@mcvps.waw.pl"
             echo -e "start - Starting Minecraft Server "
             echo -e "stop - If Minecraft Server is runnig will be stopped"
             echo -e "restart - The server will be stopped and restarted, or running if the server is down"
             echo -e "view - Connection to the server screen session"
             echo -e "live - The script check for bukkit PID from main bukkit directory, if return false server will started"
             exit 1 ;;
          *)
             echo "Use the MC with the parameter start / stop / view / restart with or without parameters to display the menu"
             exit 0 ;;
         esac
      done
      exit 1
else
             echo "Use the MC with the parameter start / stop / view / restart with or without parameters to display the menu"
             exit 1
fi

Sample for monit

/etc/monit/conf.d/minecraft

check process minecraft with pidfile /home/minecraft/.minecraft_server/server.pid
  start program = "/usr/bin/MC start"
  stop  program = "/usr/bin/MC stop"
  if 5 restarts within 5 cycles then timeout

Comments

Posts Quoted:
Reply
Clear All Quotes