Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Sep 23rd, 2011  |  syntax: Bash  |  size: 1.58 KB  |  views: 76  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. . /etc/rc.conf
  4. . /etc/rc.d/functions
  5. . /etc/conf.d/craftbukkit
  6.  
  7. save_stop() {
  8.     su -s /bin/bash -c "tmux send-keys 'save-off' C-m" craftbukkit
  9.     su -s /bin/bash -c "tmux send-keys 'save-all' C-m" craftbukkit
  10. }
  11.  
  12. save_start() {
  13.     su -s /bin/bash -c "tmux send-keys 'save-on' C-m" craftbukkit
  14. }
  15.  
  16. case "$1" in
  17.   start)
  18.     stat_busy "Starting craftbukkit daemon"
  19.  
  20.     PID=`pgrep -f -n 'craftbukkit-0.0.1-SNAPSHOT.jar'`
  21.    
  22.     if [ -z "$PID" ]; then
  23.       # RUN
  24.       su -s /bin/bash -c "tmux new-session -d 'cd ${WORKING_DIR}; java ${JAVA_ARGS} -jar /usr/share/java/craftbukkit/craftbukkit-0.0.1-SNAPSHOT.jar nogui'" craftbukkit
  25.       if [ $? -gt 0 ]; then
  26.         stat_fail
  27.         exit 1
  28.       else
  29.         add_daemon craftbukkit
  30.         stat_done
  31.       fi
  32.     else
  33.       stat_fail
  34.       exit 1
  35.     fi
  36.     ;;
  37.  
  38.   stop)
  39.     stat_busy "Stopping craftbukkit daemon"
  40.     PID=`pgrep -f -n 'craftbukkit-0.0.1-SNAPSHOT.jar'`
  41.     # KILL
  42.     [ ! -z "$PID" ] && kill $PID &> /dev/null
  43.     #
  44.     if [ $? -gt 0 ]; then
  45.       stat_fail
  46.       exit 1
  47.     else
  48.       rm_daemon craftbukkit
  49.       stat_done
  50.     fi
  51.     ;;
  52.  
  53.   restart)
  54.     $0 stop
  55.     sleep 3
  56.     $0 start
  57.     ;;
  58.  
  59.   backup)
  60.     stat_busy "Starting backup"
  61.     BACKUP_FILE="${BACKUP_DIR}/`date +%Y%m%d%H%M`.tar.gz"
  62.     su -s /bin/bash -c "mkdir -p ${BACKUP_DIR}" craftbukkit
  63.     save_stop
  64.     su -s /bin/bash -c "tar -czf ${BACKUP_FILE} ${WORLD_DIR}" craftbukkit
  65.     save_start
  66.     stat_done "Backup finished"
  67.     ;;
  68.  
  69.   *)
  70.     echo "usage: $0 {start|stop|restart}"
  71. esac
  72.  
  73. exit 0