User:M3tal Warrior/Server Startup Script

From Minecraft Wiki
Jump to: navigation, search

Since there are issues with the other startup script provided (and it is not very comfortable), I added my initscript here. For Version 1.10 I rewrote it almost completely, most noticable the update (you can now check for update without stopping the server, it restarts only if there's a new version), the backup (rsync now and no more indexing - noone needs multiple backups per minute) and the command invocations.

NOTE: This is a Debian Squeeze script which needs rsync and screen installed. I'd say it works on Ubuntu too, but haven't tested it.

Contents

[edit] Script

#!/bin/bash
# /etc/init.d/minecraft

### BEGIN INIT INFO
# Provides:   minecraft
# Required-Start: $local_fs $remote_fs
# Required-Stop:  $local_fs $remote_fs
# Should-Start:   $network
# Should-Stop:    $network
# Default-Start:  2 3 4 5
# Default-Stop:   0 1 6
# Short-Description:    Minecraft server
# Description:    Starts the minecraft server
### END INIT INFO

# ================================= Copyright =================================
# Version 1.10 (2012-01-19), Copyright (C) 2011-2012
# Author: M3tal_Warrior (http://www.minecraftwiki.net/wiki/User:M3tal_Warrior)

#   This script is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   any later version.
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.

#   As this is a one file script, theres no copy of the GNU General
#   Public License distributed along with this script.
#   See <http://www.gnu.org/licenses/> for the licence text.


# DISCLAIMER: This script contains work of another person, to the current 
#             author only known as "Hound", who might claim copyright on some
#             parts of it. Everything else is covered by aforesaid statement.

# ================================= Settings ==================================
# Here you can change almost everything for the script to fill your needs.
# For more information view the commented script at 
# http://www.minecraftwiki.net/wiki/M3tal_Warrior_Server_Startup_Script

SERVICE='minecraft_server.jar'
OPTIONS='nogui'
USERNAME='metalwarrior'
WORLD='world'
# Only use RAMFS when knowing exactly what you do!
USERAMFS='yes'
# Only relevant when USERAMFS is set to 'yes'
USERAMDIR='minecraft'
SERVERPATH='/home/minecraft/server'
BACKUPPATH='/home/minecraft/backup'
CPU_COUNT=2
INVOCATION="java -Xmx1024M -Xms1024M -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing \
           -XX:ParallelGCThreads=$CPU_COUNT -XX:+AggressiveOpts -jar $SERVICE $OPTIONS"
MCUPDATEURL="https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar"

# ---------------------------------- Addons ----------------------------------- 
# Section for programs and tools that don't come naturally with the server and
# need separate installation and configuration. Note that if you don't install
# them there are some invocations of the script you won't be able to use (but
# apparently won't miss either).

ADDONPATH='/home/minecraft/tools'

# Minecraft Biome Extractor
MBEPATH="$ADDONPATH/biome-extractor"
MBESERVICE='MinecraftBiomeExtractor.jar'
MBEINVOCATION="java -jar $MBEPATH/$MBESERVICE -nogui $WORLD"

# Minecraft Overviewer
MOPATH="$ADDONPATH/overviewer"
MOSERVICE='overviewer.py'
MOSETTINGS="$MOPATH/settings.py"
MOINPATH="$SERVERPATH/$WORLD"
MOOUTPATH="$MOPATH/mcmap"
MOADMINSETTINGS="$MOPATH/admin_settings.py"
MOADMINPATH="$MOPATH/mcadminmap"

# ================================== Modules ==================================
# The script is highly modular to allow for fast and effective modification by
# the server admin. 

# --------------------- Server command processing section ---------------------
# These commands prepare for direct interaction with the minecraft server by 
# using the buildin commands. Every such module name starts with mcc_.

# Interaction (in and out) itself is processed by mcc_pipe.
mcc_pipe() {
  mc_user "screen -p 0 -S minecraft -X eval 'stuff \"$PIPE\"\015'"
  MCNOW=`date +"%Y-%m-%d %H:%M:%S"`
  sleep 1
  cat "$MCPATH/server.log" | grep "$MCNOW"
}

# Ban players
mcc_ban() {
  if [ "$VALUE1" ]
    then 
      PIPE="ban $VALUE1"
      mcc_pipe
    else
      echo "Must specify who shall be banned!"
      exit 1
  fi
}

# Ban IPs
mcc_banip() {
  if [ "$VALUE1" ]
    then 
      PIPE="ban-ip $VALUE1"
      mcc_pipe
    else
      echo "Must specify what IP shall be banned!"
      exit 1
  fi
}

# View banlists (both player and IPs)
mcc_banlist() {
  if [[ "$VALUE1" = "ips" ]]
    then PIPE="banlist ips"
  elif [[ "$VALUE1" = "" ]]
    then PIPE="banlist"
    else 
      echo "No such command!"
      exit 1
  fi
  mcc_pipe
}

# Deop an operator
mcc_deop() {
  if [ "$VALUE1" ]
    then 
      PIPE="deop $VALUE1"
      mcc_pipe
    else
      echo "Must specify who to deop!"
      exit 1
  fi
}

# Change gamemode for named player
mcc_gamemode() {
  if [ "$VALUE1" ]
    then 
      if [ "$VALUE2" ]
        then 
          PIPE="gamemode $VALUE1 $VALUE2"
          mcc_pipe
        else
          echo "Must specify the gamemode (0/1)!"
          exit 1
      fi
    else
      echo "Must specify for whom the gamemode shall be changed!"
      exit 1
  fi
}

# Give named player an (theoretically) unlimited number of items/blocks with
# given damage value. Note: If you type in 2 damage values, the script will 
# give the player for every damage value within the range the number of items/
# blocks chosen. It does NOT check if those exist! BE CAREFUL!
mcc_give() {
  if [ "$VALUE1" ]
    then   
      if [ "$VALUE2" ]
        then
          if [[ "$VALUE3" = "" ]]
            then VALUE3="1"
          fi
        else 
          echo "Must specify what shall be given!"
          exit 1   
      fi  
    else 
      echo "Must specify to whom shall be given!"
      exit 1
  fi
  MULT=`expr $VALUE3 / 64`
  REST=`expr $VALUE3 % 64`
  while [[ "$MULT" -ge "0" ]]
    do
      if [[ "$MULT" = "0" ]]
        then VALUE3="$REST"
        else VALUE3="64"
      fi
      MULT=`expr $MULT - 1`
      if [ "$VALUE4" ]
        then
          if [ "$VALUE5" ]
	    then 
              DAMAGE="$VALUE4"
              while [[ "$DAMAGE" -le "$VALUE5" ]]
                do
                  PIPE="give $VALUE1 $VALUE2 $VALUE3 $DAMAGE"
                  mcc_pipe
                  DAMAGE=`expr $DAMAGE + 1`
                done
            else 
              PIPE="give $VALUE1 $VALUE2 $VALUE3 $VALUE4"
              mcc_pipe
          fi
        else
          PIPE="give $VALUE1 $VALUE2 $VALUE3"
          mcc_pipe
      fi
    done
}

# Displays every command available
mcc_help() {
  echo "Available commands are:"
  echo '* ban <player>'
  echo '* ban-ip <IP-address>'
  echo '* banlist'
  echo '* banlist ips'
  echo '* deop <player>'
  echo '* gamemode <player> <0|1>'
  echo '* give <player> <data-value> [<amount>]'
  echo '       [<damage-value [begin]>] [<damage-value [end]>]'
  echo '* help (shows you this list)'
  echo '* kick <player>'
  echo '* list'
  echo '* op <player>'
  echo '* pardon <player>'
  echo '* pardon-ip <IP-address>'
  echo '* save-all'
  echo '* save-off'
  echo '* save-on'
  echo '* say <"message">'
  echo '* stop'
  echo '* tell <player> <"message">'
  echo '* time <set|add> <number>'
  echo '* toggledownfall'
  echo '* tp <player> <destination player>'
  echo '* whitelist <add|remove> <player>'
  echo '* whitelist <list>'
  echo '* whitelist <on|off>'
  echo '* whitelist <reload>'
  echo '* xp <player> <amount>'
  echo "See http://www.minecraftwiki.net/wiki/SMP_Server_commands for info"
}

# Kick named player from the server
mcc_kick() {
  if [ "$VALUE1" ]
    then 
      PIPE="kick $VALUE1"
      mcc_pipe
    else
      echo "Must specify who to kick!"
      exit 1
  fi
}

# List all players currently connected to the server
mcc_list() {
  PIPE="list"
  mcc_pipe
}

# Promote player to operator
mcc_op() {
  if [ "$VALUE1" ]
    then
      PIPE="op $VALUE1"
      mcc_pipe
    else
      echo "Must specify who to op!"
      exit 1
  fi
}

# Pardon a formerly banned player
mcc_pardon() {
  if [ "$VALUE1" ]
    then 
      PIPE="pardon $VALUE1"
      mcc_pipe
    else
      echo "Must specify who to pardon!"
      exit 1
  fi
}

# Pardon a formerly banned IP
mcc_pardonip() {
  if [ "$VALUE1" ]
    then 
      PIPE="pardon-ip $VALUE1"
      mcc_pipe
    else
      echo "Must specify which IP to pardon!"
      exit 1
  fi
}

# Save all changes to the server files
mcc_saveall() {
  PIPE="save-all"
  mcc_pipe
}

# Prohibit the server saving to its files
mcc_saveoff() {
  PIPE="save-off"
  mcc_pipe
}

# Allow the server saving to its files
mcc_saveon() {
  PIPE="save-on"
  mcc_pipe
}

# Sends a pink server message out
mcc_say() {
  if [ "$VALUE1" ]
    then 
      PIPE="say $VALUE1"
      mcc_pipe
    else
      echo "Must specify what to say!"
      exit 1
  fi
}

# Gracefully shuts down the server
mcc_stop() {
  PIPE="stop"
  mcc_pipe
}

# Whisper a message to named player
mcc_tell() {
  if [ "$VALUE1" ]
    then 
      if [ "$VALUE2" ]
        then 
          PIPE="tell $VALUE1 $VALUE2"
          mcc_pipe
        else
          echo "Must specify what to whisper!"
          exit 1
      fi
    else
      echo "Must specify whom to whisper to!"
      exit 1
  fi
}

# Modify ingame time
mcc_time() {
  if [ "$VALUE1" ]
    then
      if [ "$VALUE2" ]
        then 
          PIPE="time $VALUE1 $VALUE2"
          mcc_pipe
        else
          echo "Must specify the amount of time!"
          exit 1
      fi
    else
      echo "Must specify what to do!"
      exit 1
  fi
}

# Toggle rain/snow and sunshine
mcc_toggledf() {
  PIPE="toggledownfall"
  mcc_pipe
}

# Teleport one player to another player
mcc_tp() {
  if [ "$VALUE1" ]
    then 
      if [ "$VALUE2" ]
        then 
          PIPE="tp $VALUE1 $VALUE2"
          mcc_pipe
        else
          echo "Must specify to whom to teleport!"
          exit 1
      fi
    else
      echo "Must specify whom to teleport!"
      exit 1
  fi
}

# Managing the whitelist
mcc_whitelist() {
  if [[ "$VALUE1" = "add" || "$VALUE1" = "remove" ]]
    then 
      if [ "$VALUE2" ] 
        then PIPE="whitelist $VALUE1 $VALUE2"
        else
          echo "Must specify who to add/remove from whitelist!"
          exit 1
      fi
  elif [[ "$VALUE1" = "on" || "$VALUE1" = "off" ]]
    then PIPE="whitelist $VALUE1"
  elif [[ "$VALUE1" = "reload" || "$VALUE1" = "list" ]]
    then PIPE="whitelist $VALUE1"
    else
      echo "Must specify what you want to do with your whitelist!"
      exit 1
  fi
  mcc_pipe
}

# Gives named player a defined amount of experience orbs
mcc_xp() {
  if [ "$VALUE1" ]
    then 
      if [[ "$VALUE2" = "" ]]
        then
          echo "Must specify the amount of xp!"
          exit 1
      fi
    else
      echo "Must specify whom to give xp!"
      exit 1
  fi
  MULT=`expr $VALUE2 / 5000`
  REST=`expr $VALUE2 % 5000`
  while [[ "$MULT" -ge "0" ]]
    do
      if [[ "$MULT" = "0" ]]
        then VALUE2="$REST"
        else VALUE2="5000"
      fi
      MULT=`expr $MULT - 1`
      PIPE="xp $VALUE1 $VALUE2"
      mcc_pipe
    done
  exit 0
}

# --------------------- General command processing section --------------------
# These modules are for managing the server itself and its environment. Some of
# them use the modules above, but not all of them. Every module in here has mc_
# as prefix.

# Ensures the minecraft server and its commands to always run as a certain user
# defined in this script (see settings section at the top)
mc_user() {
  if [ $ME == $USERNAME ] ; then
    bash -c "$1"
  else
    su - $USERNAME -c "$1"
  fi
}

# Checks if the server is running
mc_check() {
  if ps ax | grep -v grep | grep -v -i SCREEN | grep $SERVICE > /dev/null
    then CHECK="1"
    else CHECK=""
  fi
}

# Manages the RAMFS option
mc_upramfs() {
  if [ $USERAMFS == 'yes' ]
    then
      mkdir -p $RAMPATH
      echo "Copying files to RAMFS..."
      rsync --stats -rlpthu $SERVERPATH/ $RAMPATH
      echo "Done."
  fi
}

# Starts the server 
mc_start() {
  echo "Starting $SERVICE..."
  cd $MCPATH
  mc_user "screen -dmS minecraft $INVOCATION"
  sleep 7
  mc_check
  if [ "$CHECK" ]
    then
      echo "$SERVICE is now running."
    else
      echo "Error! Could not start $SERVICE!"
      exit 1
  fi
}

# Disables the server saving to its files
mc_saveoff() {
  if [ "$CRON" != "1" ]
    then
      echo "$SERVICE is running... suspending saves"
      VALUE1="Server going readonly..."
      mcc_say
  fi
  mcc_saveoff
  mcc_saveall
  sync
  sleep 10
}

# Enables the server saving to its files
mc_saveon() {
  if [ "$CRON" != "1" ]
    then 
      echo "$SERVICE is running... re-enabling saves"
      VALUE1="Server going read-write..."
      mcc_say
  fi
  mcc_saveon
}

# Shuts the server down
mc_stop() {
  mc_check
  if [ "$CHECK" ]
    then
      echo "Stopping $SERVICE"
      VALUE1="SERVER SHUTTING DOWN IN 10 SECONDS."
      mcc_say
      mcc_saveall
      sleep 10
      mcc_stop
      sleep 7
    else
      echo "$SERVICE was not running."
  fi
  mc_check
  if [ "$CHECK" ]
    then
      echo "Error! $SERVICE could not be stopped."
      exit 1
    else
      echo "$SERVICE is stopped."
  fi
  sync
}

# Writes the files in RAMFS back to harddisk
mc_saveback() {
  if [ "$USERAMFS" == "yes" ]
    then
      echo "Saving files to Harddisk..."
      rsync -rlpthu $RAMPATH/ $SERVERPATH
      echo "Done."
  fi
}

# Copys the harddisk files to a backup folder
mc_backup() {
  if [ "$CRON" != "1" ]
    then
      echo "Backing up minecraft server..."
  fi
  mc_user "rsync -rlpthu $SERVERPATH/ $BACKUPPATH/server_`date "+%Y.%m.%d_%H.%M"`"
  if [ "$CRON" != "1" ]
    then
      echo "Backup complete!"
  fi
}

# Copys the server.log for further processing and clears it afterwards
mc_newlog() {
  if [ "$CHECK" ]
    then
      cd $MCPATH
      cp server.log server.log.tmp
      echo -n "" > server.log
  fi
}

# Processes the server.log copy into specialized logfiles
mc_clearlog() {
  cd $MCPATH
  if [ -f server.log.tmp ]
    then 
      cat server.log.tmp | grep -v "94.231.101.83" | \
        grep -v "CONSOLE: Disabling level saving.." | \
        grep -v "CONSOLE: Forcing save.." | \
        grep -v "CONSOLE: Save complete." | \
        grep -v "CONSOLE: Enabling level saving.." > server.log.old
      cat server.log.tmp | grep "not white-listed" >> forbidden.log
      cat server.log.tmp | grep "WARNING" >> warnings.log
      rm server.log.tmp
  fi
}

# Updates the client
mc_update() {
  cd $MCPATH
  mc_user "wget -q -O update.tmp $MCUPDATEURL"
  if [ -f update.tmp ]
    then 
      if `diff $SERVICE update.tmp > /dev/null`
        then
          echo "You are already running the latest version of $SERVICE."
          rm update.tmp
        else
          mc_stop
          mc_saveback
          mc_backup
          mc_user "mv update.tmp $SERVICE"
          mc_start
          echo "Minecraft successfully updated."
      fi
    else echo "Minecraft update could not be downloaded."
  fi
}

# Tests for the command module to use for server commands
mc_command() {
  if [ "$CHECK" ]
    then
      COMMAND="$1"
      VALUE1="$2"
      VALUE2="$3"
      VALUE3="$4"
      VALUE4="$5"
      VALUE5="$6"
      if [[ "$COMMAND" = "ban" ]]
        then
          mcc_ban
      elif [[ "$COMMAND" = "ban-ip" ]]
        then
          mcc_banip
      elif [[ "$COMMAND" = "banlist" ]]
        then
          mcc_banlist
      elif [[ "$COMMAND" = "deop" ]]
        then
          mcc_deop
      elif [[ "$COMMAND" = "gamemode" ]]
        then
          mcc_gamemode
      elif [[ "$COMMAND" = "give" ]]
        then
          mcc_give
      elif [[ "$COMMAND" = "help" ]]
        then
          mcc_help
      elif [[ "$COMMAND" = "kick" ]]
        then
          mcc_kick
      elif [[ "$COMMAND" = "list" ]]
        then
          mcc_list
      elif [[ "$COMMAND" = "op" ]]
        then
          mcc_op
      elif [[ "$COMMAND" = "pardon" ]]
        then
          mcc_pardon
      elif [[ "$COMMAND" = "pardon-ip" ]]
        then
          mcc_pardonip
      elif [[ "$COMMAND" = "save-all" ]]
        then
          mcc_saveall
      elif [[ "$COMMAND" = "save-off" ]]
        then
          mcc_saveoff
      elif [[ "$COMMAND" = "save-on" ]]
        then
          mcc_saveon
      elif [[ "$COMMAND" = "say" ]]
        then
          mcc_say
      elif [[ "$COMMAND" = "stop" ]]
        then
          mcc_stop
      elif [[ "$COMMAND" = "tell" ]]
        then
          mcc_tell
      elif [[ "$COMMAND" = "time" ]]
        then
          mcc_time
      elif [[ "$COMMAND" = "toggledownfall" ]]
        then
          mcc_toggledf
      elif [[ "$COMMAND" = "tp" ]]
        then
          mcc_tp
      elif [[ "$COMMAND" = "whitelist" ]]
        then
          mcc_whitelist
      elif [[ "$COMMAND" = "xp" ]]
        then
          mcc_xp
        else
          echo "No such command available!"
          exit 1
      fi
    else 
      echo "Service not running!"
      exit 1
  fi
}

# ---------------------- Addon command processing section ---------------------
# Modules for addon management

# Minecraft Biome Extractor
mc_biomes() {
  cd $SERVERPATH
  $MBEINVOCATION
}

# Minecraft Overviewer (Google Maps)
mc_map() {
  $MOSERVICE --settings $MOSETTINGS $MOINPATH $MOOUTPATH
}
mc_adminmap() {
  $MOSERVICE --settings $MOADMINSETTINGS $MOINPATH $MOADMINPATH
}

# =================================== MAIN ====================================
# This is what will be processed during script invocation, since the modules 
# are only processed if called by the sections below.

# Questioning name of invocating user
ME=`whoami`

# Check for RAMFS
if [[ "$USERAMFS" == "yes" ]]
  then
    RAMPATH="/dev/shm/$USERAMDIR"
    MCPATH="$RAMPATH"
  else MCPATH="$SERVERPATH"
fi

case "$1" in
  start)
    mc_check
    if [ "$CHECK" ]
      then
        echo "Service already running!"
        exit 1
      else
        mc_upramfs
        mc_start
    fi
    ;;
  stop)
    mc_stop
    mc_saveback
    ;;
  restart)
    mc_stop
    mc_saveback
    mc_start
    ;;
  update)
    mc_update
    ;;
  save)
    if [ "$USERAMFS" == "yes" ]
      then
        mc_saveoff
        mc_saveback
        mc_saveon
      else 
        echo "This option is only available for RAMFS server mode!"
        exit 1
    fi
    ;;
  backup)
    mc_saveoff
    mc_saveback
    mc_backup
    mc_saveon
    ;;
  status)
    mc_check
    if [ "$CHECK" ]
    then
      echo "$SERVICE is running."
    else
      echo "$SERVICE is not running."
    fi
    ;;
  command)
    mc_check
    mc_command "$2" "$3" "$4" "$5" "$6" "$7"
    ;;
  cronbackup)
    CRON="1"
    mc_backup
    ;;
  cronsave)
    CRON="1"
    mc_saveoff
    mc_saveback
    mc_saveon
    ;;
  cronupdtmap)
    CRON="1"
    if ps -e | grep overviewer.py > /dev/null
	then exit 0
	else 
          mc_biomes
	  mc_map
    fi
    ;;
  cronupdtadminmap)
    CRON="1"
    if ps -e | grep overviewer.py > /dev/null
        then exit 0
        else 
          mc_biomes
          mc_adminmap
    fi
    ;;
  cronlog)
    CRON="1"
    mc_check
    mc_newlog
    mc_clearlog
    ;;
  *)
    echo "Usage: /etc/init.d/minecraft {start|stop|save|update|backup|status|restart| \
          command \"server command\"}"
    exit 1
    ;;
esac

exit 0

There are 2 lines that end in a backslash - bash usually replaces that with the next line beginning with the first non-empty character. Do it manually, since I only added them for reading purposes in here - they're not in my script and it might cease working if you let them in. The two lines are the java invocation in the settings section and the last echo in the script.

[edit] General Options

The script is able to work with Cron (the Linux sheduler) and use two tools (for map displaying as a google maps interface in your browser). Normally you only need to change the variables in the beginning, everything else is defined by them (as in the original script too).

  • SERVICE
If you renamed your minecraft_server.jar, show the script how you named it. Otherwise it will cry and do nothing ;)
  • OPTIONS
Well, just one option ('nogui'), because you don't need it. Start your server and type "screen -r" in your terminal to have your server gui ([CTRL]+[a] and [d] will detach screen from your terminal again without affecting the server). For more information see the manpage of screen.
  • USERNAME
Your server user name (the one you log in on your machine), NOT your minecraft account.
  • WORLD
Unless you're not hosting multiple worlds you may leave it the way it is (the standard way). If you decided to rename your world in your server.settings file, do it here too, or Minecraft Overviewer will not be able to process your world correctly. (Insider info: This variable is no longer used for backup, since the original backup routine was not backing up the server completely)
  • USERAMFS
This way your server will be transferred to your RAM at startup and run out of your RAM. Therefore you have the advantage of a super fast server without delays due to HDD reading, but the great disadvantage of less RAM available for running processes and CERTAIN data loss when your server suffers a power loss or is shut down a wrong way.
  • It is strongly recommended to use Cron for very frequent savebacks to your server directory on your HDD!
Choose the frequency on the decision how much you want to redo in a worst case scenario, since rsync needs just one or two seconds to write back the data, but the more often you save, the more often your HDD has to be waked. 10 Minutes is good, but if your server is running 24/7 for years without problems, you can increase up to the backup time you set.
  • Invocation for Cron: "/etc/init.d/minecraft cronsave"
  • For a map of about 25 km² you'll have to calculate a directory size between 500 and 600 MB, which will be subtracted from your free RAM.
  • To activate the option set the variable to 'yes'.
  • USERAMDIR
Since some people use the RAM for working on documents (and other stuff) it is a good idea to create a unique directory in your RAM to separate the server from everything else. Choose a name you like or leave it be (Default: 'minecraft').
  • This option is only used when USERAMFS is set to 'yes'.
  • SERVERPATH
Defines the path to your server and world files (without trailing slash), e.g. '/var/minecraft/server'
  • BACKUPPATH
Defines the path to your server and world files backup directory (without trailing slash), e.g. '/home/myusername/minecraft_backups'
  • CPUCOUNT
Defines how many cores of your machine minecraft/java is allowed to use at the same time. Will be either 1 (Intel Pentium series), 2 (Intel Core2Duo series), 4 (Intel Core2Quad series and above) or more. If you don't know anything about the subject, leave it with 1 - the server is most certainly not eating up your system resources.
  • INVOCATION
Don't change it - it is good as it is. For those of you who know it better: the Xmx and Xms statements are most likely the things you're looking for to increase/decrease.


[edit] Addon Options

If you install some addons to your minecraft server (NOT BUKKIT!!!) that help you getting through (i.e. the minecraft overviewer), you might change something here. Otherwise just leave it and the attached options be.

  • ADDONPATH
Defines the path to your addons, which should NOT be inside your server path. A possible example is '/var/minecraft/addons'
  • MBEPATH
Path to the biome extractor, which is needed by overviewer to display biomes on your browser map right. Can be something like "$ADDONPATH/biome-extractor", if you have placed the .jar in a subdirectory of the addon tree. Bash will replace the example with "/var/minecraft/addons/biome-extractor" (like magic, but better).
  • MBESERVICE
Name of the biome extractor .jar file.
  • MBEINVOCATION
No need to change that, if you haven't messed up the three variables before.
  • MOPATH
Path to minecraft overviewer (only the setting files, since they provide a repository for Debian - just install with apt).
  • MOSERVICE
If you installed with repository, there's no need to change anything here. If you did it otherwise, you WILL have to edit the script in the invocation section!
  • MOSETTINGS / MOADMINSETTINGS
By default there are two different setting files for my server, since I'd like to see a little bit more than my users (like what they do underground). Change it or leave it, your call. You just type the paths here, like "$MOPATH/settings.py"
  • MOINPATH
If you were able to start your server and set the WORLD variable right, there's no need to change anything here, at least if you run your server in USERAMFS mode, because this should NOT be the location of the files the server is running on. For people who run their servers from HDD, provide a path with the COPY of your server world directory here. (note to self: have to implement that)
  • MOOUTPATH / MOADMINPATH
The two paths where the generated maps and the website files will be stored, first for users (standard settings file, see MOSETTINGS variable above), second for privileged users/admins (see MOADMINSETTINGS variable).

[edit] Installation

Copy and modify the script above, write it to a file and put it into /etc/init.d. Don't forget to chmod it to executable! Afterwards it's a short

/etc/init.d/minecraft start

in the terminal to start the server. If there is no server file yet, do an update first:

/etc/init.d/minecraft update

NOTE: At least the path provided in "SERVERPATH" has to be existing, otherwise the script won't work! After the start there will be some whining from the minecraft server (no files present!), but it will start and create the files needed for running (like ops.txt, server.settings, whitelist.txt and others, including a folder named "world", where your map is saved).

[edit] Cron

For Cron there are separate invocations, since visual feedback is usually not very interesting for it.

  • cronsave
This is only for people who have USERAMFS set to 'yes'. Without that option, the script will do nothing, as will Cron.
  • cronbackup
This will backup the whole directory provided by "SERVERPATH" to a directory named after the date and time of creation inside the provided "BACKUPPATH", including every settings file and the minecraft_server.jar, so you can rollback with a single mv if things go rimwards. If you backup more than once a minute, the script will just update the existing folder.
  • cronupdtmap
Overviewer is not able to provide a live map but has to rerender it time after time - i.e. if you run that command. No worries if you have cron running and overviewer did not finish the last rendering - if there is one instance of overviewer running on your machine, this command is skipped automatically. Note: The first rendering will take a LOT of time, depending on your machine and the size of your map. For 25 km² and a Core2Duo E2200 it's roundabout 50 minutes per map/overlay. All updates will be way faster (2-4 minutes for everything - scanning for updates is the most time consuming part).
  • cronupdtadminmap
Same as above, just for the other map/settings file.
  • cronlog
It rearranges your logfile and splits it into different files:
  • server.log.old
This is the old server.log, without every line containing the following phrases:
  • 94.231.101.83
This is a server which checks for the minecraft server to be online. If you haven't announced your server in public, you won't recognize anything, if you have, you'll save yourself about 150 entries a day.
  • Disabling level saving..
If you have Cron running cronsave or cronbackup, you'd see that every time it runs in your original server.log
  • CONSOLE: Forcing save..
Same as above
  • CONSOLE: Save complete.
Same as above
  • CONSOLE: Enabling level saving..
Same as - Yeah, I know, it's a curse, that's why I remove them from the file.
You may add a line of your own, just go to the mc_clearlog section in the script, copy one of the middle lines to the following and modify that.
  • forbidden.log
If your server is white-listed, every connection attempt that is rejected by the server is logged here.
  • warnings.log
Contains every warning the server is printing to the server.log, and only those. Useful for finding griefers who attempt to fly and so on...

[edit] Commands

While running the server type

/etc/init.d/minecraft command help

to see a whole list of available commands and invocations. All of them are serverside options you already know from the console. There are only two major tweaks to them:

  • GIVE/XP
You're now able to give your players almost any amount of things - the script will calculate how often it has to pipe the command to the server utilizing the maximum amount (64 for give, 5000 for xp) per invocation. So giving 1000 stone or 1,000,000 experience to anybody with a single command won't be a problem any longer. NOTICE: The script will only pipe the command once per second, due to feedback reasons and flooding prevention (which whould be easily possible). If you want to skip that, delete the line "sleep 1" in mcc_pipe, but that might give you a major lag if you're being very generous!
  • GIVE - Damage value
Since I'd like to give everybody on my server the whole set of maps with a single command, I included a "damage value range". So if you provide a second damage value like
/etc/init.d/minecraft command give Player 358 1 0 24
the script will give "Player" 25 maps, beginning with map_0 until map_24 (inclusive), one each. Combined with the ability to skip the amount limit, the script will do one cycle of one stack per damage value and afterwards redo that as often as it calculated to reach the desired amount (2 cycles for =<128 items, 3 for up to 192 and so on). I think I'll change that in the future...

Naturally these commands are only available with the console, you can't escape the game and invocate the script with the provided chat utility.

[edit] Problems & Ideas

If you encounter some bugs or have some ideas to implement in here please let me know either on the discussion page of this article or in my own. I'll try my best!

Personal tools
Namespaces
Variants
Actions
Minecraft Wiki
Minecraft
Toolbox

Recent Community Articles

Mojang Tweets

    Getting your tweets...