#!/bin/sh
# Start script for FreeBSD, contributed by user Fabian Abplanalp
# Put this script in /usr/local/etc/rc.d then adjust MINECRAFT_BIN and
# MINECRAFT_CFG values in /etc/defaults/minecraft

MINECRAFT_BIN="/usr/local/bin/minecraft.jar"
MINECRAFT_CFG="/usr/local/etc/minecraft.conf"
MINECRAFT_PID="/var/run/minecraft.pid"


# Read configuration variable file if it is present
[ -r /etc/defaults/minecraft ] && . /etc/defaults/minecraft

case "$1" in
  "start")
    echo "Starting minecraft..."
    java -Xmx2048M -Xms2048M -jar MINECRAFT_BIN nogui &
    echo $! > ${MINECRAFT_PID}
    echo "done"
  ;;

  "stop")
    echo "Stopping minecraft..."
    if [ -f ${MINECRAFT_PID} ] ; then
      kill `cat ${MINECRAFT_PID}`
      rm ${MINECRAFT_PID}
      echo "done"
    else
      echo "not running?"
    fi
  ;;

  "restart")
    echo "Restarting minecraft..."
    $0 stop
    sleep 2
    $0 start
  ;;

  *)
    echo "$0 [start|stop|restart]"
  ;;

esac
