Craftbukkit Init Script for use with Mysql

Discussion in 'Bukkit Tools' started by giffordj, Dec 7, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    giffordj

    I looked around numerous times trying to find a script that took care of all the necessary dependencies when running Craftbukkit with MySQL. The issue I was that MySQL started after Craftbukkit. So I took it upon myself and wrote my own bootscript.

    I'm running Ubuntu Server 12.04 64bit - PermissionsEx and MySQL.

    12/8/2012 - Made some tweaks based off of comments received. Thank you.
    12/8/2012 - More comments received. Updates made to prevent errors on offline backup

    Please review and comment:

    Code:
    #!/bin/bash
    # /etc/init.d/craftbukkit
    # version 2012-12-08 (YYYY-MM-DD)
     
    ### BEGIN INIT INFO
    # Provides:            craftbukkit
    # Required-Start:      $local_fs $remote_fs $mysql
    # Required-Stop:        $local_fs $remote_fs $mysql
    # Should-Start:        $network
    # Should-Stop:          $network
    # Default-Start:        2 3 4 5
    # Default-Stop:        0 1 6
    # Short-Description:    CraftBukkit Server
    # Description:          Starts the CraftBukkit Server
    ### END INIT INFO
     
    # craftbukkit-init-script - An initscript to start CraftBukkit
    # Copyright (C) 2012 - Jim Gifford <[email protected]>
    #
    # This program 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
    # (at your option) 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.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program.  If not, see <http://www.gnu.org/licenses/>.
     
    # Script is configured to used with Ubuntu, but should be easily modified
    # for other versions of linux as well.
     
    ###########################################################################
    # Cron Information
    #
    # With crontab -e as the user that's running CraftBukkit add the following
    # lines.
    #
    # The 1st line checks the server and restarts if necessary
    # The 2nd line does a complete backup at 3:00am daily
    # The 3rd line does a maps backup every 3 hours
    # The 4th line rotates the logs at 12:01 am
    # The 5th line removes old backups every 10 hours
    #
    #  */30 * * * * /etc/init.d/craftbukkit check_status
    #  00 3 * * * /etc/init.d/craftbukkit backup
    #  00 */3 * * * /etc/init.d/craftbukkit backup_maps
    #  05 0 * * * /etc/init.d/craftbukkit log_rotate
    #  00 */10 * * * /etc/init.d/craftbukkit remove_old_backups
    #
    # End of Configuration Variables
    ###########################################################################
     
    ###########################################################################
    # Bash Information
    #
    # To use the script in a friendly manner add the following to your
    # ~/.bash_aliases file
    #
    # nano ~/.bash_aliases
    # alias craftbukkit='/etc/init.d/craftbukkit'
    #
    # End of Bash Information
    ###########################################################################
     
    ###########################################################################
    # Sudoers Information
    #
    # To use the script in a friendly manner add the following to your
    # /etc/sudoers file
    #
    # sudo nano /etc/sudoers
    # # For CraftBukkit Server
    # bukkit localhost = NOPASSWD: /etc/init.d/craftbukkit
    # bukkit localhost = NOPASSWD: /usr/bin/chrt
    #
    # End of Sudoers Information
    ###########################################################################
     
    ###########################################################################
    # Installation Information
    #
    # To auto start the script use the following command
    #
    # sudo update-rc.d craftbukkit defaults
    #
    # End of Installation Information
    ###########################################################################
     
    ###########################################################################
    # Configuration Variables
    #
    ## CraftBukkit Settings
    #
    # Identifies Service in script
    #
    CB_SERVICE_NAME=CraftBukkit
    #
    # Server Jar File
    #
    CB_JAR_NAME=craftbukkit.jar
    #
    # Username of user who will run the server
    #
    CB_USERNAME=bukkit
    #
    # Location of the Server Jar File
    #
    CB_PATH=/home/bukkit/craftbukkit
    #
    # Which Permission Plugin are you using
    #  options are:
    #  pex    for PermissionsEx
    #  none    for all others
    #
    CB_PERMISSIONS=pex
     
    ## Tmux Settomgs
    #
    # Name of Tmux session name
    #
    TMUX_SESSION_NAME=bukkit
    #
     
    ## Backup Settings
    #
    # Where backups go
    #  Location of where backups belong
    #
    CB_BACKUP_PATH=/home/bukkit/backups
    #
    # How many backups of the jar executable
    #
    CB_BACKUP_JAR_RETAIN=1
    #
    # How many backups of the mysql databases to keep
    #
    CB_BACKUP_MYSQL_RETAIN=7
    #
    # How many backups of the plugins to keep
    #
    CB_BACKUP_PLUGINS_RETAIN=7
    #
    # How many backups of the worlds to keep
    #
    CB_BACKUP_WORLDS_RETAIN=25
    #
    # How many days of logs should we keep
    #
    CB_LOGS_RETAIN=7
     
    ## Mysql Information
    #
    # Mysql User
    #
    CB_MYSQL_USER_NAME=MySQL_User
    #
    # Mysql Password
    #
    CB_MYSQL_PASSWORD=MySQL_Password
     
    ## Java Settings
    #
    # Number of CPU Cores
    #
    # This will automatically figure out how many CPU's or CPU Core's are installed.
    # If you want to configure this manually just put in a number
    JAVA_CPU=$(cat /proc/cpuinfo | grep -c processor)
    #
    # Java Options
    #
    JAVA_OPTS="-D64 -Xms2G -Xmx6G -Xss2048k -Djava.net.preferIPvStack=true -XX:MaxPermSize=128M -XX:UseSSE=3 -XX:-DisableExplicitGC -XX:+UseParallelOldGC -XX:ParallelGCThreads=$JAVA_CPU"
    #
    # Set the priroity of Java using chrt
    # First Option
    # -f    = set policy to SCHED_FIFO
    # -r    = set policy to SCHED_RR
    # Second Option
    # -p 50 = Scheduling Priority  usually a number between 50 and 70
    #
    JAVA_PRIORITY="-f -p 50"
     
    #
    # End of Configuration Variables
    ###########################################################################
     
    ##########################################################################
    # Run Commands - Do not Change
    #
    # Java Start
    #
    JAVA_RUN="java -server $JAVA_OPTS -jar $CB_JAR_NAME nogui"
     
    # Command used to run Tmux
    #
    TMUX_RUN="tmux send -t $TMUX_SESSION_NAME"
    #
     
    #
    # End of Run Commands
    ###########################################################################
     
    ###########################################################################
    # Script Common Routines
    #
     
    ## Source LSB function library
    #
    if [ -f /lib/lsb/init-functions ]
    then
    source /lib/lsb/init-functions
    fi
     
    ## Runs all commands as the non-root user
    #
    run_as() {
      MY_USERNAME=$(whoami)
      if [ $MY_USERNAME == $CB_USERNAME ]
      then
        bash -c "$1"
      else
        sudo -u $CB_USERNAME -i bash -c "$1"
      fi
    }
     
    run_as_root() {
      MY_USERNAME=$(whoami)
      if [ $MY_USERNAME == root ]
      then
        bash -c "$1"
      else
        sudo -i bash -c "$1"
      fi
    }
     
    ## Create Symlinks and Move Maps for backups
    #
    create_symlinks() {
    cd $CB_PATH
    if ! [ -e worlds ]
    then
      mkdir worlds
    fi
    WORLDS=$(find * -name 'level.dat' | cut -f1 -d'/' | sed -e '/worlds/d')
    for world in $WORLDS
    do
      echo "  Moving $world to worlds/world..."
      run_as "cd $CB_PATH && mv $world worlds/$world"
      echo "  Creating sysmlink for $world..."
      run_as "cd $CB_PATH && ln -snf worlds/$world $world"
    done
    }
     
    ## Check if the server is running or not, and get PID if it is
    #
    server_running() {
      if ps ax | grep -v grep | grep -iv tmux | grep -iv sh | grep $CB_JAR_NAME > /dev/null
      then
        PID=0
        PID="$(ps ax | grep -v grep | grep -iv tmux | grep -iv sh | grep $CB_JAR_NAME | awk '{print $1}')"
        return 0
      else
        return 1
      fi
    }
     
    ## Set the server to read-only mode
    #
    save_off() {
      if server_running
      then
        echo "  Commencing map save procedures for $CB_SERVICE_NAME..."
        echo "    Notifying users of save mode change..."
        run_as "$TMUX_RUN 'say SERVER BACKUP STARTING. Server going to read-only mode...' C-m"
        echo "    Notification to users completed..."
        echo "    Setting server read-only..."
        run_as "$TMUX_RUN 'save-off' C-m"
        echo "    Server is now in read-only mode..."
        echo "  Saving maps to disk..."
        run_as "$TMUX_RUN 'save-all' C-m"
        sync
        sleep 10
        echo "  Saving of maps completed..."
      else
        echo " $CB_SERVICE_NAME was not running. Not suspending saves..."
        exit 1
      fi
    }
     
    ## Set the server read-write mode
    #
    save_on() {
      if server_running
      then
        echo "  Re-enabling saves on $CB_SERVICE_NAME..."
        echo "    Notifying users of save mode change..."
        run_as "$TMUX_RUN 'say SERVER BACKUP ENDED. Server going to read-write mode...' C-m"
        echo "    Notification to users completed..."
        echo "  Setting server read-write..."
        run_as "$TMUX_RUN 'save-on' C-m"
        echo "  Server is now in read-write mode..."
      else
        echo " $CB_SERVICE_NAME was not running. Not resuming saves..."
        exit 1
      fi
    }
     
    #
    # End of Script Common Routines
    ###########################################################################
     
    ###########################################################################
    # Init Script Functions
    #
     
    ## Start CraftBukkit as a service
    #
    do_start() {
      if server_running
      then
        log_failure_msg " $CB_SERVICE_NAME was already running! (pid $PID)"
        exit 1
      else
        create_symlinks
        log_daemon_msg " Starting $CB_SERVICE_NAME..."
        run_as "cd $CB_PATH && tmux new -d -n $CB_SERVICE_NAME -s $TMUX_SESSION_NAME '$JAVA_RUN'"
        sleep 10
        log_daemon_msg "  Checking $CB_SERVICE_NAME is running..."
     
        if server_running
        then
          log_success_msg " $CB_SERVICE_NAME is now running. (pid $PID)"
        else
          log_failure_msg " Could not start $CB_SERVICE_NAME..."
          exit 1
        fi
     
        if server_running
        then
          log_daemon_msg " Setting Java to run in Real-Time..."
          run_as_root "chrt $JAVA_PRIORITY $PID"
        fi
     
      fi
    }
     
    ## Check if server is running and display PID
    #
    do_status() {
      if server_running
      then
        echo " $CB_SERVICE_NAME (pid $PID) is running..."
      else
        echo " $CB_SERVICE_NAME is not running..."
        exit 1
      fi
    }
     
    ## Stop CraftBukkit
    #
    do_stop() {
      if server_running
      then
        log_daemon_msg " Commencing shutdown procedures for $CB_SERVICE_NAME..."
        log_daemon_msg "  Notifying users of shutdown..."
        run_as "$TMUX_RUN 'say SERVER SHUTTING DOWN IN 10 SECONDS. Saving maps...' C-m"
        log_success_msg "  Notification to users completed..."
        log_daemon_msg "  Saving maps to disk..."
        run_as "$TMUX_RUN 'save-all' C-m"
        sleep 10
        log_success_msg "  Saving of maps completed..."
        log_daemon_msg "  Stopping $CB_SERVICE_NAME..."
        run_as "$TMUX_RUN 'stop' C-m"
        sleep 10
      else
        log_failure_msg " $CB_SERVICE_NAME was not running!"
        exit 1
      fi
     
      if server_running
      then
        log_failure_msg "  $CB_SERVICE_NAME could not be shutdown! Still running..."
        exit 1
      else
        log_success_msg " $CB_SERVICE_NAME is shut down..."
        create_symlinks
      fi
    }
     
    #
    # End of Init Script Functions
    ###########################################################################
     
    ###########################################################################
    # Cron Script Functions
    #
     
    ## Back-up JAR executable
    #
    do_backup_jar() {
      if [ "$OFFLINE" = "no" ]
      then
        run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Backing up server jar...' C-m"
      fi
      echo "  Backing up the $CB_SERVICE_NAME server jar..."
      run_as "cd $CB_PATH && cp $CB_JAR_NAME $CB_BACKUP_PATH/$CB_JAR_NAME\_backup\_$CURRENT_TIME.jar && md5sum $CB_BACKUP_PATH/$CB_JAR_NAME\_backup\_$CURRENT_TIME.jar > $CB_BACKUP_PATH/$CB_JAR_NAME\_backup\_$CURRENT_TIME.jar.md5"
      echo "  Backing up the $CB_SERVICE_NAME server jar completed..."
      run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Backing up server jar completed...' C-m"
    }
     
    ## Back-up mysql
    #
    do_backup_mysql() {
      echo "  Backing up the $CB_SERVICE_NAME MySQL databases..."
      if [ "$OFFLINE" = "no" ]
      then
        run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Backing up MySQL databases...' C-m"
      fi
      run_as "rm -rf $CB_BACKUP_PATH/mysql_dump && mkdir $CB_BACKUP_PATH/mysql_dump"
      CB_DATABASES=$(mysql --user="$CB_MYSQL_USER_NAME" --password="$CB_MYSQL_PASSWORD" -Bse "show databases" | sed -e '/information_schema/d' -e '/test/d')
      for database in $CB_DATABASES
      do
        run_as "cd $CB_BACKUP_PATH/mysql_dump && mysqldump --user=\"$CB_MYSQL_USER_NAME\" --password=\"$CB_MYSQL_PASSWORD\" \"$database\" > \"$database.sql\""
      done
      echo "  Creating compressed backup for MySQL databases..."
      if [ "$OFFLINE" = "no" ]
      then
        run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Compressing server MySQL databases backup...' C-m"
      fi
      CURRENT_TIME="$(date +%Y-%m-%d.%H-%M-%S)"
      sleep 10
      run_as "cd $CB_BACKUP_PATH && tar cJf mysql_backup_$CURRENT_TIME.tar.xz mysql_dump && md5sum mysql_backup_$CURRENT_TIME.tar.xz > mysql_backup_$CURRENT_TIME.tar.xz.md5"
      if [ "$OFFLINE" = "no" ]
      then
        run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Compressing server MySQL databases backup completed...' C-m"
      fi
      run_as "rm -rf $CB_BACKUP_PATH/mysql_dump"
      echo "  Backing up the $CB_SERVICE_NAME MySQL databases completed..."
      if [ "$OFFLINE" = "no" ]
      then
        run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Backing up MySQL databases completed...' C-m"
      fi
    }
     
    ## Back-up plugins
    #
    do_backup_plugins() {
      if [ "$CB_PERMISSIONS" == "pex" ]
      then
          if [ "$OFFLINE" = "no" ]
          then
            echo "  Dumping Permissions to Flat File..."
            run_as "$TMUX_RUN 'pex dump sql permissions.sql' C-m"
            echo "  SQL Dumped of Permissions to Flat File completed..."
        fi
      fi
      echo "  Backing up the $CB_SERVICE_NAME server plugins..."
      run_as "rm -rf $CB_BACKUP_PATH/plugins && mkdir $CB_BACKUP_PATH/plugins"
      if [ "$OFFLINE" = "no" ]
      then
        run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Backing up server plugins...' C-m"
      fi
      echo "    Syncing $CB_PATH/plugins to $CB_BACKUP_PATH/plugins"
      run_as "cd $CB_PATH && rsync -chLoprtu plugins $CB_BACKUP_PATH"
      echo "    Creating compressed backup for server plugins..."
      if [ "$OFFLINE" = "no" ]
      then
        run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Compressing server plugins backup...' C-m"
      fi
      CURRENT_TIME="$(date +%Y-%m-%d.%H-%M-%S)"
      sleep 10
      run_as "cd $CB_BACKUP_PATH && tar cJf plugins_backup_$CURRENT_TIME.tar.xz plugins && md5sum plugins_backup_$CURRENT_TIME.tar.xz > plugins_backup_$CURRENT_TIME.tar.xz.md5"
      if [ "$OFFLINE" = "no" ]
      then
        run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Compressing server plugins backup completed...' C-m"
      fi
      echo "  Backing up the $CB_SERVICE_NAME server plugins completed..."
      if [ "$OFFLINE" = "no" ]
      then
        run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Backing up server plugins completed...' C-m"
      fi
    }
     
    ## Back-up worlds
    #
    do_backup_worlds() {
      echo "  Backing up $CB_SERVICE_NAME all worlds..."
      run_as "rm -rf $CB_BACKUP_PATH/worlds && mkdir $CB_BACKUP_PATH/worlds"
      if [ "$OFFLINE" = "no" ]
      then
        run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Backing up all maps...' C-m"
      fi
      echo "    Syncing $CB_PATH/worlds to $CB_BACKUP_PATH/worlds"
      run_as "cd $CB_PATH && rsync -chLoprtu worlds $CB_BACKUP_PATH"
      sleep 10
      if [ "$OFFLINE" = "no" ]
      then
        run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Backing up all maps completed...' C-m"
        run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Compressing maps backup...' C-m"
      fi
      echo "  Creating compressed backup of all worlds..."
      CURRENT_TIME="$(date +%Y-%m-%d.%H-%M-%S)"
      sleep 10
      run_as "cd $CB_BACKUP_PATH && tar cJf worlds_backup_$CURRENT_TIME.tar.xz worlds && md5sum worlds_backup_$CURRENT_TIME.tar.xz > worlds_backup_$CURRENT_TIME.tar.xz.md5"
      if [ "$OFFLINE" = "no" ]
      then
        run_as "$TMUX_RUN 'say SERVER BACKUP STATUS. Compressing maps backup completed...' C-m"
      fi
      echo "  Creating compressed backup of all worlds completed..."
    }
     
    ## Check status of server - restart if needed
    #
    do_check_status() {
      if server_running
      then
      echo " $CB_SERVICE_NAME (pid $PID) is running..."
      else
      echo " $CB_SERVICE_NAME was not running! Restarting"
      do_start
      fi
    }
     
    ## Rotates log files keeps the last 7
    #
    do_log_rotate() {
      echo " Rotation of log files..."
      LOG_FILE=$(ls -r $CB_PATH/server.log* | grep -v lck)
      for i in $LOG_FILE; do
        LOGO_FILE_TMP=$(ls $i | cut -d "." -f 3)
        if [ -z $LOGO_FILE_TMP ]
        then
          LOGO_FILE_TMP="$CB_PATH/server.log"
          LOG_FILE_NEW="$LOGO_FILE_TMP.1"
          run_as "cp $CB_PATH/server.log $LOG_FILE_NEW"
        elif [ $LOGO_FILE_TMP -gt $$CB_LOGS_RETAIN ]
        then
          run_as "rm -f $i"
        else
          LOG_BASE_NAME=$(ls $i | cut -d "." -f 1-2)
          LOG_FILE_NEW=$LOG_BASE_NAME.$(($LOGO_FILE_TMP+1))
          run_as "cp $i $LOG_FILE_NEW"
        fi
      done
      run_as "echo -n \"\" > $CB_PATH/server.log"
      echo " Rotation of log files completed..."
    }
     
    ## Removes any backups older than 7 days
    #
    do_remove_old_backups() {
      echo "Removing older backups..."
      CB_BACKUPS="worlds_backup $CB_JAR_NAME\_backup plugins_backup mysql_backup"
      for backup in $CB_BACKUPS
      do
        if [ "$backup" = "$CB_JAR_NAME\_backup" ]
        then
          RETAIN_NUMBER_BACKUPS=$CB_BACKUP_JAR_RETAIN
        fi
        if [ "$backup" = "plugins_backup" ]
        then
          RETAIN_NUMBER_BACKUPS=$CB_BACKUP_PLUGINS_RETAIN
        fi
        if [ "$backup" = "mysql_backup" ]
        then
          RETAIN_NUMBER_BACKUPS=$CB_BACKUP_MYSQL_RETAIN
        fi
        if [ "$backup" = "worlds_backup" ]
        then
          RETAIN_NUMBER_BACKUPS=$CB_BACKUP_WORLDS_RETAIN
        fi
        NUMBER_OF_BACKUPS=$(ls $CB_BACKUP_PATH/$backup* | sed -e '/\.md5/d' | wc -l)
        OLDEST_BACKUP=$(ls $CB_BACKUP_PATH/$backup* | sed -e '/\.md5/d' | head -n 1)
        if [ $NUMBER_OF_BACKUPS -gt $RETAIN_NUMBER_BACKUPS ]
        then
          echo "Removing file $OLDEST_BACKUP..."
          run_as "rm -rf $OLDEST_BACKUP $OLDEST_BACKUP.md5"
        fi
      done
      echo "Removing older backups completed..."
    }
     
    #
    # End of Cron Script Functions
    ###########################################################################
     
    ###########################################################################
    # End of cron Routines
    #
     
    ## Send Command to Console
    #
    do_command() {
      if server_running
      then
        echo "Enter the command you would like to send"
        echo -n "type EXIT to exit -=>"
        read CB_COMMAND
        if [ "$CB_COMMAND" = "EXIT" ]
        then
          exit 0
        fi
        if [ "$CB_COMMAND" != "" ]
        then
          SEND_SERVER_LOG_SIZE=$(wc -l $CB_PATH/server.log | awk '{print $1}')
          run_as "$TMUX_RUN '$CB_COMMAND' C-m"
          sleep 1
          tail -n $[`wc -l $CB_PATH/server.log  | awk '{print $1}'`-$SEND_SERVER_LOG_SIZE] $CB_PATH/server.log
        fi
      else
      echo " $CB_SERVICE_NAME was not running!"
      exit 1
    fi
    do_command
    }
     
    ## Activate Console Session
    #
    do_console() {
      if server_running
      then
        run_as "tmux attach -t $TMUX_SESSION_NAME"
      else
      echo " $CB_SERVICE_NAME was not running!"
      exit 1
      fi
    }
     
    ## Display some extra environment informaton
    #
    do_info() {
      if server_running
      then
        MEMORY_USED="$(ps -p $PID --format rss | tail -n 1)"
        echo " - CraftBukkit JAR    : $CB_PATH/$CB_JAR_NAME"
        echo " - Java Path          : $(readlink -f $(which java))"
        echo " - Java Command      : $JAVA_RUN"
        echo " - Memory Usage      : $[$MEMORY_USED/1024] Mb ($MEMORY_USED kb)"
        echo " - Process Owner      : $(ps -p $PID -o "%u" | tail -n 1)"
        echo " - Process ID        : $PID"
        echo " - Backup Path        : $CB_BACKUP_PATH"
        echo " - Tmux Session Name  : $TMUX_SESSION_NAME"
        echo " - Active Connections : "
        lsof -i :$(cat $CB_PATH/server.properties | grep -E 'server-port' | sed -e s/.*server-port=//)
      else
        echo " $CB_SERVICE_NAME is not running..."
        exit 1
      fi
    }
     
    #
    # End of Cron Script Functions
    ###########################################################################
     
    ###########################################################################
    # Script Menu
    #
    case "$1" in
      ################################################################
      #### Init Script Functions
      #
      # Restart Service
      #
      restart)
        do_stop
        sleep 5
        do_start
      ;;
      # Start Service
      #
      start)
        do_start
      ;;
      # Check Status of Service
      #
      status)
        do_status
      ;;
      # Stop Service
      #
      stop)
        do_stop
      ;;
      #
      #### End Init Script Functions
      ################################################################
     
      ################################################################
      #### Cron Script Functions
      #
      # Complete Backup of Server
      #
      backup)
        OFFLINE=no
        save_off
        do_backup_worlds
        do_backup_jar
        do_backup_plugins
        do_backup_mysql
        save_on
      ;;
      # Backup the maps on the Server
      #
      backup_maps)
        save_off
        do_backup_worlds
        save_on
      ;;
      # Check status of server
      #
      check_status)
        do_check_status
      ;;
      # Remove Rotate Log Files - CRON JOB
      #
      log_rotate)
        do_log_rotate
      ;;
      # Remove Old Backups - CRON JOB
      #
      remove_old_backups)
        do_remove_old_backups
      ;;
      #
      #### End of Cron Script Functions
      ################################################################
     
      ################################################################
      #### General Use Script Functions
      #
      # Info on the Service
      #
      # Show Console
      #
      console)
        do_console
      ;;
      info)
        do_info
      ;;
      # Backup Files when server is off-line
      #
      offline_backup)
        if server_running
        then
          echo " Can't use offline_backup when the server is running..."
        else
          OFFLINE=yes
          create_symlinks
          do_backup_worlds
          do_backup_jar
          do_backup_plugins
          do_backup_mysql
        fi
      ;;
      # Send Command to console
      #
      run_command)
        do_command
      ;;
      #
      #### End of General Use Script Functions
      ################################################################
     
      ################################################################
      #### Menu of Options
      #
      *)
        echo " Init Script Invocation:"
        echo "  Usage: $0 {restart|start|status|stop}"
        echo ""
        echo " cron Invocation:"
        echo " * Usage: $0 {backup|backup_maps|log_rotate|remove_old_backups}"
        echo ""
        echo " General User Invocation:"
        echo " * Usage: $0 {console|info|offline_backup|run_command}"
        echo ""
        echo "    console allows you to see the running server."
        echo "      use ctrl-b d to exit"
        echo "    run_command allows you to send a command to the console"
        echo "      It will prompt you for input"
        echo ""
        exit 1
      ;;
    esac
      #
      #### Menu of Options
      ################################################################
     
    # End of Script Menu
    ###########################################################################
     
    
     
Thread Status:
Not open for further replies.

Share This Page