Merge pull request #308 from donkers/master

pre and post 1.7.0 log support
This commit is contained in:
Blaine Motsinger 2015-08-22 10:47:52 -05:00
commit b27e2c3100
5 changed files with 16 additions and 15 deletions

View File

@ -57,9 +57,6 @@ follow_links "$COMPLETION"; COMPLETION="$RETURN"
### Config variables the user should not need/want to change
# The start of a regex to find a log line
LOG_REGEX="^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} \[.*\]"
# Lazy allocation status
ALLOCATED_SERVERS="false"
ALLOCATED_WORLDS="false"
@ -295,7 +292,7 @@ now() {
# $1: A server log line
# returns: Time in seconds since 1970-01-01 00:00:00 UTC
log_line_get_time() {
time_string="$(echo "$1" | awk '{print $1 " " $2}')"
time_string="$(echo "$1" | awk -F'[] [/:]+' '{print $1 " " $2 ":" $3 ":" $4}')"
date -d "$time_string" "+%s" 2> /dev/null
}
@ -807,12 +804,11 @@ server_worlds_to_disk() {
server_log_get_line() {
server_property "$1" USERNAME
server_property "$1" LOG_PATH
server_property "$1" CONSOLE_EVENT_REGEX
unset RETURN
# Make sure there is a server log to check
as_user "${SERVER_USERNAME[$1]}" "touch ${SERVER_LOG_PATH[$1]}"
local regex="${LOG_REGEX} ($3)"
local regex="${SERVER_CONSOLE_EVENT_OUTPUT_REGEX[$1]} ($3)"
local timeout_deadline=$(( $(now) + $4 ))
# Read log, break if nothing is read in $4 seconds
@ -828,7 +824,7 @@ server_log_get_line() {
RETURN="${BASH_REMATCH[1]}"
return 0
fi
done < <(as_user "${SERVER_USERNAME[$1]}" "tail --pid=$$ --follow --lines=20 --sleep-interval=0.1 \"${SERVER_LOG_PATH[$1]}\"")
done < <(as_user "${SERVER_USERNAME[$1]}" "tail --pid=$$ --follow=name --retry --lines=20 --sleep-interval=0.1 \"${SERVER_LOG_PATH[$1]}\" 2>/dev/null")
}
# The same as server_log_get_line, but prints a dot instead of the log line
@ -841,11 +837,9 @@ server_log_get_line() {
server_log_dots_for_lines() {
server_property "$1" USERNAME
server_property "$1" LOG_PATH
server_property "$1" CONSOLE_EVENT_REGEX
# Make sure there is a server log to check
as_user "${SERVER_USERNAME[$1]}" "touch ${SERVER_LOG_PATH[$1]}"
local regex="${LOG_REGEX} ($3)"
local regex="${SERVER_CONSOLE_EVENT_OUTPUT_REGEX[$1]} ($3)"
local timeout_deadline=$(( $(now) + $4 ))
# Read log, break if nothing is read in $4 seconds
@ -866,7 +860,7 @@ server_log_dots_for_lines() {
return 0
fi
fi
done < <(as_user "${SERVER_USERNAME[$1]}" "tail --pid=$$ --follow --lines=100 --sleep-interval=0.1 \"${SERVER_LOG_PATH[$1]}\"")
done < <(as_user "${SERVER_USERNAME[$1]}" "tail --pid=$$ --follow=name --retry --lines=100 --sleep-interval=0.1 \"${SERVER_LOG_PATH[$1]}\" 2>/dev/null")
}
# Sends as string to a server for execution
@ -3151,7 +3145,7 @@ command_server_cmdlog() {
echo "Now watching logs (press Ctrl+C to exit):"
echo "..."
server_eval "$1" "${*:2}"
as_user "${SERVER_USERNAME[$1]}" "tail --pid=$$ --follow --lines=5 --sleep-interval=0.1 ${SERVER_LOG_PATH[$1]}"
as_user "${SERVER_USERNAME[$1]}" "tail --pid=$$ --follow=name --retry --lines=5 --sleep-interval=0.1 ${SERVER_LOG_PATH[$1]} 2>/dev/null"
else
error_exit SERVER_STOPPED "Server \"${SERVER_NAME[$1]}\" is not running."
fi

View File

@ -137,7 +137,7 @@ DEFAULT_COMPLETE_BACKUP_FOLLOW_SYMLINKS="false"
# The location of standard Minecraft server files, relative to the
# server directory
DEFAULT_LOG_PATH="server.log"
DEFAULT_LOG_PATH="logs/latest.log"
DEFAULT_PROPERTIES_PATH="server.properties"
DEFAULT_WHITELIST_PATH="white-list.txt"
DEFAULT_BANNED_PLAYERS_PATH="banned-players.txt"

View File

@ -1,5 +1,6 @@
# MSM version file for Minecraft 1.2.0 and above
console_event REGEX "^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} \[.*\]"
console_event START:30 "Done"
console_command WHITELIST_ON "whitelist on"

View File

@ -0,0 +1,5 @@
# MSM version file for Minecraft 1.7.0 and above
extends "minecraft/1.3.0"
console_event REGEX "^\[[0-9]{2}:[0-9]{2}:[0-9]{2}\] \[.*\]:"

View File

@ -5,6 +5,7 @@
# Vanilla Minecraft versions
minecraft/1.2.0
minecraft/1.3.0
minecraft/1.7.0
# CraftBukkit versions
craftbukkit/1.2.0