Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # /etc/init.d/minecraft
- # version 2.01 2013-11-09
- # by surferpup
- # Starts and administers a Minecraft Server with RamDrive Option
- #
- # Script allows for Start/Stop/Restart Minecraft
- # -- will auto configure RamDrive if desired
- # Specify Java and jarfile settings
- # Show server status
- # Execute Minecraft Command
- # Reboot Server
- # Backup Mincraft (daily, weekly, etc)
- # Manage Hourly/Daily/Weekly/Monthly/Manual BKU files
- # Synchronize Ram Drive (if used)
- # Chime (i.e. Hourly Server Chime)
- # Random Quotes (if you provide a file)
- # Cleaning of Cron Log on Start
- # Interacts with Cron nicely
- # Displays Help
- #
- # TODO:
- #
- # Add feature to create backup directories if they do not exist
- # Create Selectable Restore from Backup
- # Error recovery (allow to auto-move world.bak to world)
- # Full install script (automate settings and setup)
- #
- #
- # NOTES: 1) I run my Feed the Beast Unleashed server on Ubunutu, and I am using mcpc+. This script accommodates these settings.
- # 2) I am using a 4GB RamDrive (/dev/shm) which I have modified in /etc/fstab to only be 4GB.
- # The RamDrive is synchronized every 5 minutes by a cron job executing this script
- # 3) I currently run two Minecraft servers on the same host with two copies of this script. For you to do so,
- # you need to make sure each instance has a different mine craft folder, a differently-named jar file, a different world location
- # and you will need customzed versions of this script for each instance (it really isn't that difficult).
- # 4) I am using HugePages -- if you want to do so, you will need to modify /etc/sysctl.conf and /etc/security/limits.conf
- # There is a great calculator for HugePages here -> http://www.peuss.de/node/67 You will need to set a user group for large pages.
- # 5) I chmod 755 the script and copied it to /etc/init.d. I then placed a symlink in /usr/local/bin (ln -s /etc/inti.d/minecraft /usr/local/bin)
- # This allows it to run without the ./ prefix or the .sh extension.
- # 6) I also modified rc.local to execute this script on startup by adding the following command (which also sends messages to my log file):
- # sudo -u surferpup /etc/init.d/minecraft start >> /home/surferpup/minecraft.cronlog 2>&1
- # 7) I am including my crontab entries below (sudo crontab -e to edit yours).
- # 8) For backups to work properly, you must create a backup folder outside of the Minecraft Install, and subfolders in that folder named as follows:
- # hourly,daily,weekly,monthly,manual
- # Make sure to set the number of backup files in each class you wish to keep.
- # 8) This script is working well on a production server of 10-12 players, although it would work for any size server.
- # -- I literally pay no mind to the server now, it just runs. Enjoy.
- #
- # CHANGELOG
- # VER DATE CHANGE
- # ----- ------------- ----------------------------------------------------------------------------
- # 2.01 2013-11-09 -- Corrected problem in mc_resstart and _mc_reboot where giving backup option
- # would not issue user warnings.
- ########################################################
- ### CRONTAB ENTRIES EXAMPLE -- for automating functions
- #########################################################
- # These entries will execute accoringly and send output to logifle.
- # m h dom mon dow command
- # Random Quote - at 18,33 and 48 Minutes every hour except 7 am.
- # 18,33,48 0-6,8-23 * * * su -c '/etc/init.d/minecraft quote >> /home/surferpup/minecraft.cronlog 2>&1' -s /bin/sh surferpup
- # Restart Minecraft with Daily Backup Odd Days at 7 am (30 minute warning starts at 6:30)
- # 30 6 1-31/2 * * su -c '/etc/init.d/minecraft restart daily >> /home/surferpup/minecraft.cronlog 2>&1' -s /bin/sh surferpup
- # Reboot Server with Daily Backup Even Days at 7 am(30 minute warning starts at 6:30)
- # 30 6 2-30/2 * * su -c '/etc/init.d/minecraft reboot daily >> /home/surferpup/minecraft.cronlog 2>&1' -s /bin/sh surferpup
- # Synchronize RamDrive every 5 Minutes except at minute 0 (backups/restarts and chimes run then)
- # 5-55/5 * * * * su -c '/etc/init.d/minecraft ramdrivesave >> /home/surferpup/minecraft.cronlog 2>&1' -s /bin/sh surferpup
- # Hourly Chime with Backup (not at 7 am -- restart or reboot will run)
- # 0 0-6,8-23 * * * su -c '/etc/init.d/minecraft chime hourly >> /home/surferpup/minecraft.cronlog 2>&1' -s /bin/sh surferpup
- # Note: Weekly and Monthly Backup handled automatically by script. Goal is to not duplicate backups.
- # If Daily backups fall on first of week or first of month, then the script will change them to weekly or monthly surferpup
- #
- #
- ########################################################
- ### MINECRAFT SERVER SETTINGS
- ########################################################
- #echo "Number of args = $#"
- JARFILE="mcpcp.jar" # Jarfile of Minecraft server
- SERVICENAME="minecraft" # if running multiple MC Servers on same host -- each need different name
- USERNAME="surferpup" # Username to run Minecraft under
- MCSTORE="/home/$USERNAME/UnleashedServer" # Hard drive location of Minecraft files and world directory
- RAMPATH="/dev/shm/minecraft_ramdisk" # RamDisk location of Minecraft files and world directory
- WORLD=world # Name of world folder (used with MCSTORE and MCPATH)
- USE_RAMDRIVE=1 # Use Ram Disk No = 0, Yes = 1
- SCRIPTLOG="/home/$USERNAME/$SERVICENAME.cronlog" # Log file for script messages. Auto clened in the start script.
- BACKUPPATH="/home/$USERNAME/minecraft_backups" # Backup Directory and Path
- MANUALBACKUPS=10 # Number of manual backups to keep
- HOURLYBACKUPS=24 # Number of hourly backups to keep
- DAILYBACKUPS=7 # Number of daily backups to keep
- WEEKLYBACKUPS=4 # Number of weekly backups to keep
- MONTHLYBACKUPS=12 # Number of monthly backups to keep
- RANDOMQUOTEFILE="/home/surferpup/ChimeTastic" # File path of Random Quotes (Blank if none)
- ########################################################
- ### JAVA-SPECIFIC SETTINGS
- ########################################################
- CPU_COUNT=8 # Number of CPU Cores (for Java Garbage Collector)
- # # JAVA INVVOCATION STRING
- INVOCATION="java \
- -Xmx8G \
- -Xmn2G \
- -XX:PermSize=2G \
- -XX:MaxPermSize=2G \
- -XX:TargetSurvivorRatio=80 \
- -XX:MaxTenuringThreshold=31 \
- -XX:+UseParNewGC \
- -XX:ParallelGCThreads=`expr $CPU_COUNT - 1` \
- -XX:+UseConcMarkSweepGC \
- -XX:+UseGCOverheadLimit \
- -XX:+DisableExplicitGC \
- -XX:MaxGCPauseMillis=500 \
- -XX:GCPauseIntervalMillis=150 \
- -XX:+AggressiveOpts \
- -XX:+TieredCompilation \
- -XX:ReservedCodeCacheSize=2G \
- -XX:+UseCodeCacheFlushing \
- -XX:CompileThreshold=1000 \
- -XX:+UseLargePages \
- -XX:LargePageSizeInBytes=2m \
- -jar $JARFILE nogui"
- ########################################################
- ### INITIALIZE SHELL VARIABLES -- DO NOT MODIFY
- ########################################################
- # Path to Minecraft files and world directory
- if [ $USE_RAMDRIVE -eq 1 ] && [ ! -n "$OPTION" -a "$OPTION" != " " ] ; then
- MCPATH=$RAMPATH
- else
- MCPATH=$MCSTORE
- fi
- COMMANDLINE=$@ # Commandline as typed by user
- COMMAND=$1 # First commandline argument (used for function select)
- OPTION=$2 # Second commandline argument
- TO_SCREEN="screen -p 0 -S $SERVICENAME -X eval 'stuff " # Key Variable for screen session functionality
- BACKUPTYPES=("hourly" "daily" "weekly" "monthly" "manual") #Backup types allowed
- DEFAULTBACKUP="manual" # Default Backup Type (lower case - must have directory)
- WARNING_NOUN="The Server" # Noun for Warning Message
- WARNING_VERB="rebooted" # Reboot/Restart warning message.
- ########################################################
- ### FORCE USER TO DESIGNATED USER (Used extensively)
- ########################################################
- as_user() {
- if [ "`whoami`" == "$USERNAME" ] ; then
- bash -c "$1"
- else
- su - $USERNAME -c "$1"
- fi
- }
- ########################################################
- ### RAMDRIVE HELPER FUNCTION -- Synchronize
- ########################################################
- mc_ramdrivesave() {
- if [ "$USE_RAMDRIVE" == "1" ]; then
- if [ ! -f $MCPATH/$JARFILE ]; then
- echo `date +"%Y.%m.%d-%r: Error.. Minecraft not in ramdrive"`
- else
- echo `date +"%Y.%m.%d-%r: Saving ramdrive to disk."`
- if [ -d "$MCSTORE/$WORLD.bak" ]; then
- echo `date +"%Y.%m.%d-%r: last $WORLD.bak still exist, crashed warning! manual check required!!!"`
- exit 1
- fi
- if [ -d "$MCSTORE/$WORLD" ]; then
- as_user "mv $MCSTORE/$WORLD $MCSTORE/$WORLD.bak"
- fi
- if mc_status; then
- # Minecraft currently running, so save world
- as_user "$TO_SCREEN \"save-off\"\015'"
- as_user "$TO_SCREEN \"save-all\"\015'"
- as_user "rsync -r -t $MCPATH/ $MCSTORE/"
- as_user "$TO_SCREEN \"save-on\"\015'"
- echo `date +"%Y.%m.%d-%r: Ram Drive Synchronization complete ... world save turned back on."`
- else
- # Minecraft currently not running
- echo `date +"%Y.%m.%d-%r: Synchronizing Ram Drive, screen session closed"`
- as_user "rsync -r -t $MCPATH/ $MCSTORE/"
- fi
- if [ -d "$MCSTORE/$WORLD.bak" ]; then
- as_user "rm -r $MCSTORE/$WORLD.bak"
- fi
- fi
- else
- echo `date +"%Y.%m.%d-%r: ramdrivesave: Ram Drive not in use."`
- fi
- }
- ########################################################
- ### SERVER REBOOT
- ### Useage: minecraft reboot
- ### minecraft reboot now
- ### minecraft reboot <backup option>
- ########################################################
- mc_reboot_server() {
- echo `date +"%Y.%m.%d-%r: Commencing server reboot."`
- if [ -z "$OPTION" ] || contains ; then
- if mc_status ; then
- echo `date +"%Y.%m.%d-%r: Reboot process initated with user warnings."`
- WARNING_NOUN="The server"
- WARNING_VERB="rebooted"
- mc_warning
- fi
- else
- if [ "$OPTION" == "now" ]; then
- echo `date +"%Y.%m.%d-%r: Reboot initated WITHOUT user warnings."`
- else
- echo ""
- echo "Bad option: $COMMANDLINE"
- echo ""
- mc_showhelp
- exit 1
- fi
- fi
- if mc_status; then
- mc_stop
- else
- echo `date +"%Y.%m.%d-%r: Prior to reboot, $JARFILE not running."`
- fi
- if contains ; then # backup requested prior to reboot
- echo `date +"%Y.%m.%d-%r: Prior to reboot, $(echo $OPTION | perl -ne 'print ucfirst($_)') backup requested."`
- mc_backup
- fi
- echo `date +"%Y.%m.%d-%r: Rebooting server..."`
- as_user "reboot"
- }
- #######################################################
- ### MINECRAFT START, STOP, RESTART, STATUS, COMMAND
- ### Useage: minecraft start
- ### minecraft stop
- ### minecraft restart
- ### minecraft restart now
- ### minecraft restart <backup option>
- ### minecraft status
- ### minecraft command <"command in quotes">
- #######################################################
- mc_start() {
- if mc_status; then
- echo `date +"%Y.%m.%d-%r: Tried to start but $JARFILE was already running!"`
- else
- echo `date +"%Y.%m.%d-%r: $JARFILE was not running... starting."`
- if [ -d $MCSTORE/$WORLD.bak ]; then
- echo `date +"%Y.%m.%d-%r: last $WORLD.bak still exist, crashed warning! manual check required!!!"`
- exit 1
- fi
- if [[ ( ! -f "$MCPATH/$JARFILE" || "$OPTION" == "reload" ) && $USE_RAMDRIVE -eq 1 ]]; then
- if [ "$OPTION" == "reload" ]; then
- echo `date +"%Y.%m.%d-%r: Reloading Ram Drive ... Remove old drive."`
- as_user "rm -r $RAMPATH"
- echo `date +"%Y.%m.%d-%r: Old Ram Drive removed .. reloading Ram Drive from Hard Drive..."`
- else
- echo `date +"%Y.%m.%d-%r: Ram drive empty... prepping."`
- fi
- as_user "rsync -r -t $MCSTORE/ $MCPATH/"
- echo `date +"%Y.%m.%d-%r: Ram drive prepared."`
- fi
- if [ ! -f "$MCPATH/$JARFILE" ]; then
- echo "Minecraft path $MCPATH does not contain $JARFILE. Aborting."
- exit 1
- fi
- echo `date +"%Y.%m.%d-%r: Cleaning Script Cron Log ... "`
- tail -1500 $SCRIPTLOG > $SCRIPTLOG$(echo tmp); mv $SCRIPTLOG$(echo tmp) $SCRIPTLOG
- cd $MCPATH
- echo "Starting Minecraft from $MCPATH/$JARFILE...."
- as_user "cd $MCPATH && screen -dmS $SERVICENAME $INVOCATION"
- sleep 7
- if mc_status; then
- echo `date +"%Y.%m.%d-%r: $JARFILE is now running."`
- else
- echo `date +"%Y.%m.%d-%r: Could not start $JARFILE."`
- fi
- fi
- }
- mc_stop() {
- if mc_status; then
- echo `date +"%Y.%m.%d-%r: $JARFILE is running... stopping."`
- as_user "$TO_SCREEN \"say SERVER SHUTTING DOWN IN 5 SECONDS. Saving map...\"\015'"
- as_user "$TO_SCREEN \"stop\"\015'"
- sleep 10
- else
- echo `date +"%Y.%m.%d-%r: Attempted to stop, but $JARFILE was not running."`
- fi
- if mc_status; then
- echo `date +"%Y.%m.%d-%r: $JARFILE could not be shut down... still running."`
- else
- mc_ramdrivesave # Synchronize Ramdrive with Hardrive if in use.
- echo `date +"%Y.%m.%d-%r: $JARFILE is shut down."`
- fi
- }
- mc_restart() {
- echo `date +"%Y.%m.%d-%r: Commencing Minecraft Restart."`
- if [ -z "$OPTION" ] || contains ; then
- if mc_status ; then
- echo `date +"%Y.%m.%d-%r: Minecraft Restart process initated with user warnings."`
- WARNING_NOUN="Minecraft"
- WARNING_VERB="restarted"
- mc_warning
- fi
- else
- if [ "$OPTION" == "now" ]; then
- echo `date +"%Y.%m.%d-%r: Minecraft Restart process initated WITHOUT user warnings."`
- else
- echo ""
- echo "Bad option: $COMMANDLINE"
- echo ""
- mc_showhelp
- exit 1
- fi
- fi
- if mc_status; then
- mc_stop
- else
- echo `date +"%Y.%m.%d-%r: Prior to restart, $JARFILE not running."`
- fi
- if contains ; then # backup requested prior to Minecraft restart
- echo `date +"%Y.%m.%d-%r: Prior to restart, $(echo $OPTION | perl -ne 'print ucfirst($_)') backup requested."`
- mc_backup
- fi
- echo `date +"%Y.%m.%d-%r: Restarting $JARFILE..."`
- mc_start
- }
- mc_status() {
- ps aux |grep -F -v grep|grep -F -v SCREEN|grep -F --quiet $JARFILE
- return $?
- }
- ##########
- ### NOTES on mc_command:
- ### Command will default to whatever the default $COMMAND variable is (usually "list")
- ### Used as a helper function to "minecraft status"
- ### IF you issue an invalid Minecraft Server command, the error will show up in the Minecraft Console
- ##########
- mc_command() {
- if [ -z $OPTION]; then
- OPTION="list"
- fi
- if pgrep -u $USERNAME -f $JARFILE > /dev/null; then
- pre_log_len=`wc -l "$MCPATH/server.log" | awk '{print $1}'`
- echo `date +"%Y.%m.%d-%r: $JARFILE is running... executing command"`
- as_user "$TO_SCREEN \"$OPTION\"\015'"
- sleep .1 # assumes that the command will run and print to the log file in less than .1 seconds
- # print output
- tail -n $[`wc -l "$MCPATH/server.log" | awk '{print $1}'`-$pre_log_len] "$MCPATH/server.log"
- fi
- }
- ########################################################
- ### Backups
- ########################################################
- mc_backup() {
- # Check for vaild option
- BACKUPTYPE=$OPTION
- if [ -z $OPTION ]; then
- BACKUPTYPE=$DEFAULTBACKUP
- else
- if ! contains ; then # Check if allowed backup type
- echo ""
- echo "The backup type you chose ($BACKUPTYPE) is not defined."
- mc_showhelp
- exit 1
- fi
- fi
- echo `date +"%Y.%m.%d-%r: $(echo $BACKUPTYPE | perl -ne 'print ucfirst($_)') Backup."`
- echo `date +"%Y.%m.%d-%r: Backing up minecraft files"`
- # If using Ram Drive, synchronize Hard Drive location to Ram Drive
- if [ $USE_RAMDRIVE -ne 1 ]; then
- mc_saveoff
- else
- mc_ramdrivesave
- fi
- # On daily backups, check if day is first of month or first of week. If so, change the backup tyoe accordiningly
- if [[ ($BACKUPTYPE == "daily" || $BACKUPTYPE == "weekly") && $(echo `date +"%d"`) == 01 ]]; then
- echo `date +"%Y.%m.%d-%r: It is the first of the month, $BACKUPTYPE changed to monthly."`
- BACKUPTYPE="monthly"
- elif [[ $BACKUPTYPE == "daily" && $(echo `date +"%u"`) == 1 ]]; then
- echo `date +"%Y.%m.%d-%r: It is the first of the week, $BACKUPTYPE changed to weekly."`
- BACKUPTYPE="weekly"
- fi
- # Back up the world folder on the Hard Drive
- echo `date +"%Y.%m.%d-%r: World save done, commencing $(echo $BACKUPTYPE | perl -ne 'print ucfirst($_)') Backup to $BACKUPPATH/$BACKUPTYPE."`
- as_user "tar -czPf $BACKUPPATH/$BACKUPTYPE/MCBKUP_`date +"%Y.%m.%d-%H%M%S"`.tar.gz $MCSTORE"
- if [ $USE_RAMDRIVE -ne 1 ]; then
- mc_saveon
- fi
- echo `date +"%Y.%m.%d-%r: $(echo $BACKUPTYPE | perl -ne 'print ucfirst($_)') backup complete"`
- # Remove excess backup files (oldest first) from backup folder
- filearray=("$BACKUPPATH""/$BACKUPTYPE"/* ) #filearray will store the list of files in the directory
- numfiles=${#filearray[@]}
- maxfiles="${BACKUPTYPE^^}BACKUPS" # maxvalues = string containing name of variable for # of backups
- if [ $numfiles -gt ${!maxfiles} ]; then # Dereference maxfiles (${!maxfiles}) to get max # of backups
- REMOVED="$(echo ${filearray[@]:0:`expr $numfiles - ${!maxfiles}`})" #Dereferenced again
- echo `date +"%Y.%m.%d-%r: Removing $REMOVED"`
- as_user "rm $REMOVED"
- else
- echo `date +"%Y.%m.%d-%r: No backup files removed."`
- fi
- echo `date +"%Y.%m.%d-%r: $(echo $BACKUPTYPE | perl -ne 'print ucfirst($_)') Backup complete"`
- }
- ########################################################
- ### BACKUP HELPER FUNCTIONS
- ########################################################
- contains() {
- for element in "${BACKUPTYPES[@]}"
- do
- if [ $element == "$OPTION" ] ; then
- return 0
- fi
- done
- return 1
- }
- mc_saveoff() {
- if mc_status; then
- echo `date +"%Y.%m.%d-%r: $JARFILE is running... suspending saves"`
- as_user "$TO_SCREEN \"say SERVER BACKUP STARTING. Server going readonly...\"\015'"
- as_user "$TO_SCREEN \"save-off\"\015'"
- sleep .1
- as_user "$TO_SCREEN \"save-all\"\015'"
- sleep 10
- else
- echo `date +"%Y.%m.%d-%r: $JARFILE was not running. Not suspending saves."`
- fi
- }
- mc_saveon() {
- if mc_status; then
- echo `date +"%Y.%m.%d-%r: $JARFILE is running... re-enabling saves"`
- as_user "$TO_SCREEN \"save-on\"\015'"
- as_user "$TO_SCREEN \"say SERVER BACKUP ENDED. Server going read-write...\"\015'"
- echo `date +"%Y.%m.%d-%r: $JARFILE is running... world save turned back on."`
- else
- echo `date +"%Y.%m.%d-%r: $JARFILE was not running. Not resuming saves."`
- fi
- }
- ########################################################
- ### Hourly Chime (Optional Backup)
- ########################################################
- mc_chime() {
- local MESSAGE_WORD="without"
- if contains; then
- MESSAGE_WORD="with $(echo $BACKUPTYPE | perl -ne 'print ucfirst($_)')"
- else
- if [ ! -z $OPTION ]; then
- echo ""
- echo "Bad option: $COMMANDLINE"
- echo ""
- mc_showhelp
- exit 1
- fi
- fi
- echo `date +"%Y.%m.%d-%r: Hourly Chime $MESSAGE_WORD Backup."`
- as_user "$TO_SCREEN \"say ---------------------------------------\"\015'"
- as_user "$TO_SCREEN \"say The server time is `date +"%r CST"`.\"\015'"
- as_user "$TO_SCREEN \"say Hourly Chime Annoyance Lessification complete.\"\015'"
- as_user "$TO_SCREEN \"say NOTE: The Mining World will be respawned.\"\015'"
- as_user "$TO_SCREEN \"say PLEASE REMOVE YOUR ITEMS FROM MINING WORLD BY SUNDAY!!!\"\015'"
- as_user "$TO_SCREEN \"say ---------------------------------------\"\015'"
- sleep .1
- as_user "$TO_SCREEN \"list\"\015'"
- if contains ; then
- mc_backup
- fi
- }
- ########################################################
- ### Blurt out random Quote from Quote File (if it exists)
- ########################################################
- mc_quote() {
- if [ -f "$RANDOMQUOTEFILE" ] ; then
- as_user "$TO_SCREEN \"say RANDOM THOUGHT:\"\015'"
- sleep .1
- RANDOMTHOUGHT=$(shuf -n 1 $RANDOMQUOTEFILE)
- echo "$RANDOMTHOUGHT"
- as_user "$TO_SCREEN \"say $RANDOMTHOUGHT\"\015'"
- sleep .1
- else
- echo `date +"%Y.%m.%d-%r: There is not quotefile at $RANDOMQUOTEFILE"`
- fi
- }
- ########################################################
- ### Server Reboot/Restart Warning Message
- ########################################################
- mc_warning() {
- as_user "$TO_SCREEN \"say $WARNING_NOUN will be $WARNING_VERB in 30 minutes. Please plan your excursions accordingly.\"\015'"
- sleep 10m
- as_user "$TO_SCREEN \"say $WARNING_NOUN will be $WARNING_VERB in 20 minutes. You will be logged off when this happens.\"\015'"
- sleep 10m
- as_user "$TO_SCREEN \"say $WARNING_NOUN will be $WARNING_VERB in 10 minutes Dig Beauford!! Dig!!!!!!.\"\015'"
- sleep 5m
- as_user "$TO_SCREEN \"say $WARNING_NOUN will be $WARNING_VERB in 5 minutes. The server will be down while the backup completes.\"\015'"
- sleep 3m
- as_user "$TO_SCREEN \"say $WARNING_NOUN will be $WARNING_VERB in 2 minutes Please log out soon.\"\015'"
- sleep 1m
- as_user "$TO_SCREEN \"say $WARNING_NOUN will be $WARNING_VERB in 1 minute.\"\015'"
- as_user "$TO_SCREEN \"say $WARNING_NOUN will come back when the process completes. Please give it about 2 minutes.\"\015'"
- sleep 30
- as_user "$TO_SCREEN \"say 30 SECONDS TILL ${WARNING_NOUN^^} WILL BE ${WARNING_VERB} ...\"\015'"
- sleep 15
- as_user "$TO_SCREEN \"say 15 SECONDS TILL ${WARNING_NOUN^^} WILL BE ${WARNING_VERB} ...\"\015'"
- sleep 5
- as_user "$TO_SCREEN \"say 10 SECONDS TILL ${WARNING_NOUN^^} WILL BE ${WARNING_VERB} ...\"\015'"
- sleep 5
- as_user "$TO_SCREEN \"say 5 SECONDS TILL ${WARNING_NOUN^^} WILL BE ${WARNING_VERB} ...\"\015'"
- sleep 1
- as_user "$TO_SCREEN \"say 4 SECONDS TILL ${WARNING_NOUN^^} WILL BE ${WARNING_VERB} ...\"\015'"
- sleep 1
- as_user "$TO_SCREEN \"say 3 SECONDS TILL ${WARNING_NOUN^^} WILL BE ${WARNING_VERB} ...\"\015'"
- sleep 1
- as_user "$TO_SCREEN \"say 2 SECONDS TILL ${WARNING_NOUN^^} WILL BE ${WARNING_VERB} ...\"\015'"
- sleep 1
- as_user "$TO_SCREEN \"say 1 SECONDS TILL ${WARNING_NOUN^^} WILL BE ${WARNING_VERB} ...\"\015'"
- sleep 1
- }
- ########################################################
- ### Help Text
- ########################################################
- mc_showhelp() {
- ME=`basename $0` # The name of this script
- DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # the path of this script
- echo ""
- echo "Usage: $DIR/$ME <command> <option>"
- echo ""
- echo "Command <option> Description"
- echo "---------------- -------------------------------------------------------------------"
- echo "start <option> Start Minecraft. Option \"reload\" will recreate the RamDrive."
- echo " ex. minecraft start"
- echo " minecraft start reload"
- echo "stop Stop Minecraft gracefully."
- echo "restart <option> Restart Minecraft gracefully with backup and 30 minute user warning."
- echo " ex. minecraft restart"
- echo " minecraft restart now (Skips warning)"
- echo " minecraft restart daily (or any backup type) -- backup and restart."
- echo "reboot <option> Reboots server gracefully with backup and 30 minute user warning."
- echo " ex. minecraft reboot"
- echo " minecraft reboot now (Skips warning)"
- echo "status Shows status of server and list of current players."
- echo "command <option> Execute any minecraft server comand (option in \"\")."
- echo " ex. minecraft command \"say Hello World!\""
- echo " default option = \"list\""
- echo "backup <option> Backup the world file to $BACKUPPATH with the following options:"
- for element in "${BACKUPTYPES[@]}"
- do
- echo " $element (backup to $BACKUPPATH/$element)"
- done
- echo " default option is $DEFAULTBACKUP"
- echo " NOTE: Backups DO NOT cause a Minecraft restart.."
- echo "chime <option> Print the Chime message. Can also execute any backup type."
- echo " ex. minecraft chime"
- echo " minecraft chime hourly (or any backup type)"
- echo "ramdrivesave Force ramdisk to synch to hard drive world folder."
- echo "--------------"
- echo " Script $ME stored in $DIR. Use \"sudo nano $DIR/$ME\" to edit."
- echo ""
- }
- ########################################################
- ### COMMAND LINE ARGUMENTS
- ########################################################
- case "$COMMAND" in
- start)
- mc_start
- ;;
- stop)
- mc_stop
- ;;
- restart)
- mc_restart
- ;;
- reboot)
- mc_reboot_server
- ;;
- status)
- if mc_status; then
- echo "Minecraft is running from $MCPATH/$JARFILE."
- mc_command
- else
- echo `date +"%Y.%m.%d-%H: $JARFILE is not running."`
- fi
- ;;
- command)
- mc_command
- ;;
- backup)
- mc_backup
- ;;
- ramdrivesave)
- mc_ramdrivesave
- ;;
- chime)
- mc_chime
- ;;
- quote)
- mc_quote
- ;;
- ?)
- mc_showhelp
- exit 1
- ;;
- *)
- mc_showhelp
- exit 1
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment