HosipLan

Untitled

Oct 12th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.78 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ### BEGIN INIT INFO
  4. # Provides:          minecraft
  5. # Required-Start:    $network $remote_fs $syslog
  6. # Required-Stop:     $network $remote_fs $syslog
  7. # Default-Start:     2 3 4 5
  8. # Default-Stop:      0 1 6
  9. # Short-Description: Minecraft server
  10. ### END INIT INFO
  11.  
  12. . /lib/lsb/init-functions
  13.  
  14. test $DEBIAN_SCRIPT_DEBUG && set -v -x
  15.  
  16. NAME="minecraft"
  17. DESC="Minecraft server craftbukkit 1.3.1"
  18.  
  19. JAVA=`which java`
  20. SERVER_DIR="/home/hosiplan/minecraft"
  21. SERVER="$SERVER_DIR/craftbukkit-1.3.1-R2.0.jar"
  22. JAVA_OPTS="-Xmx2048M -Xms2048M"
  23. DAEMON_OPTS=" $JAVA_OPTS -jar $SERVER"
  24. PIDFILE="/var/run/$NAME.pid"
  25.  
  26. test -e $SERVER || exit 0
  27. test -x $JAVA || exit 0
  28.  
  29.  
  30. start_minecraft () {
  31.     STATUS=0
  32.  
  33.     # Check to see if it's already started...
  34.     if test -e /var/run/$NAME.pid ; then
  35.         log_failure_msg "Already running (PID file exists)"
  36.     else
  37.         start-stop-daemon --start --background --quiet \
  38.             --make-pidfile --pidfile $PIDFILE --chdir $SERVER_DIR \
  39.             --exec $JAVA -- $DAEMON_OPTS || STATUS=1
  40.     fi
  41.  
  42.     log_end_msg $STATUS
  43. }
  44.  
  45. stop_minecraft () {
  46.     STATUS=0
  47.  
  48.     if test -s "$PIDFILE" ; then
  49.         start-stop-daemon --stop --quiet --pidfile $PIDFILE || STATUS=1
  50.         rm -f $PIDFILE
  51.     else
  52.         log_warning_msg "  $NAME is not running."
  53.     fi
  54.  
  55.     log_end_msg $STATUS
  56. }
  57.  
  58. case "$1" in
  59.     start)
  60.         log_action_begin_msg "Starting $DESC"
  61.         start_minecraft
  62.  
  63.         exit ${STATUS:-0}
  64.     ;;
  65.     stop)
  66.         log_action_begin_msg "Stopping $DESC"
  67.         stop_minecraft
  68.  
  69.         exit ${STATUS:-0}
  70.     ;;
  71.     restart)
  72.         log_action_begin_msg "Restarting $DESC"
  73.  
  74.         stop_minecraft
  75.         sleep 1
  76.         start_minecraft
  77.  
  78.         exit ${STATUS:-0}
  79.     ;;
  80.     status)
  81.         STATUS=0
  82.         status_of_proc -p $PIDFILE $NAME "$DESC" || STATUS=1
  83.         exit $STATUS
  84.     ;;
  85.     *)
  86.         echo "Usage: $0 {start|stop|restart|status}" >&2
  87.         exit 1
  88.     ;;
  89. esac
  90.  
  91. exit 0
Advertisement
Add Comment
Please, Sign In to add comment