Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- minecraft_server Sun Dec 23 15:47:12 2012
- +++ minecraft_server Sun Dec 23 15:51:52 2012
- @@ -33,6 +33,8 @@
- # watch <world> - Watch the log file for the Minecraft world server.
- # backup <world> - Backup the Minecraft world. Backup all worlds by
- # default.
- +# logrotate <world> - Rotate the server.log file.
- +# Will rotate the server log for all worlds by default.
- # map <world> - Run the Minecraft Overviewer mapping software on
- # the Minecraft world. Map all worlds by default.
- # update <software> - Update a software package. Update the server
- @@ -162,6 +164,11 @@
- # Length in days that backups survive.
- BACKUP_DURATION=31
- +## Server Log Configuration
- +
- +# How many rotations of server.log to keep
- +LOG_COUNT=10
- +
- ## Mirror image options.
- @@ -489,6 +496,56 @@
- done
- }
- +# Rotates the world server log file.
- +#
- +# @param 1 The world server generating the log to rotate.
- +rotateLog() {
- + local WORLD_DIR LOG_LIST LOGBASE LOGTMP LOGNEW
- +
- + WORLD_DIR="$WORLDS_LOCATION/$1"
- + # Use the mirror copy of the world directory if enabled.
- + if [ $ENABLE_MIRROR -eq 1 ] && [ -d $MIRROR_PATH ]; then
- + WORLD_DIR="$MIRROR_PATH/$1"
- + fi
- +
- + # Make sure that the server.log file exists.
- + execute "touch $WORLD_DIR/server.log" $USER_NAME
- +
- + # Scan the log for entires and skip rotate is none are found
- + local log_lines="$(cat "$WORLD_DIR/server.log" | wc -l )"
- +
- + if [ "$log_lines" -le '1' ]; then
- + printf "No new log enteries to rotate. No changes made."
- + return 0
- + fi
- +
- + # Server logfiles in chronological order
- + LOGLIST=$(ls -r $WORLD_DIR/server.log* | grep -v lck)
- +
- + # Look at all the logfiles
- + for i in $LOGLIST; do
- + LOGTMP=$(ls $i | cut -d "." -f 3)
- + # If we're working with server.log, append .1 then compress it
- + if [ -z $LOGTMP ]; then
- + LOGTMP="$WORLD_DIR/server.log"
- + LOGNEW="${LOGTMP}.1"
- + execute "cp $WORLD_DIR/server.log $LOGNEW" $USER_NAME
- + execute "gzip $LOGNEW" $USER_NAME
- + # Otherwise, check if the file number is under $LOG_COUNT
- + elif [ $LOGTMP -eq $LOG_COUNT ]; then
- + # If so, delete it
- + execute "rm -f $i" $USER_NAME
- + else
- + # Otherwise, add one to the number
- + LOGBASE=$(ls $i | cut -d "." -f 1-2)
- + LOGNEW=$LOGBASE.$(($LOGTMP+1))
- + execute "cp $i $LOGNEW.gz" $USER_NAME
- + fi
- + done
- + # Blank the existing logfile to renew it
- + execute "cp \"/dev/null\" $WORLD_DIR/server.log" $USER_NAME
- +}
- +
- # Watch the world server log file.
- #
- # @param 1 The world server generating the log to watch.
- @@ -907,6 +964,17 @@
- exit 1
- fi
- ;;
- + logrotate)
- + # Figure out which worlds to rotate the log.
- + WORLDS=$(checkOptionalArgument "$ALL_WORLDS" $0 $1 $2)
- + # Backup each world requested.
- + printf "Rotating Server Log:"
- + for WORLD in $WORLDS; do
- + printf " $WORLD"
- + rotateLog $WORLD
- + done
- + printf "\n"
- + ;;
- backup)
- # Figure out which worlds to backup.
- WORLDS=$(checkOptionalArgument "$ALL_WORLDS" $0 $1 $2)
- @@ -1002,7 +1070,7 @@
- printf "\n"
- ;;
- *)
- - printf "Usage: $0 {start|stop|force-stop|restart|force-restart|status|sync|send|screen|watch|backup|update|map} {Optional: world or software package}\n"
- + printf "Usage: $0 {start|stop|force-stop|restart|force-restart|status|sync|send|screen|watch|backup|update|logrotate|map} {Optional: world or software package}\n"
- exit 1
- ;;
- esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement