Last active
December 14, 2015 08:59
-
-
Save nTraum/5061401 to your computer and use it in GitHub Desktop.
A Ruby script that uses the steam-condenser gem to move stv demos and log files from a srcds to a remote location only when the gameserver is empty.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HOST = 'example.com' | |
PORT = 27015 | |
RCON = 's3cr3t' | |
STV_SRC_DIR = '/servers/foo/orangebox/tf/demos/' #trailing slash necessary! | |
STV_DEST_DIR = '/var/www/bar/demos/' | |
STV_GLOB = '*.dem' | |
LOGS_SRC_DIR = '/servers/foo/orangebox/tf/logs/' | |
LOGS_DEST_DIR = '/var/www/bar/logs/' | |
LOGS_GLOB = '*.log' | |
COMPRESS_DEMOS = true | |
COMPRESS_COMMAND = "bzip2 -q #{STV_DEST_DIR}#{STV_GLOB} >/dev/null 2>&1" | |
begin | |
require'fileutils' | |
require 'steam-condenser' | |
rescue LoadError | |
exit | |
end | |
def server_empty? | |
begin | |
SourceServer.new(HOST, PORT).players.empty? | |
rescue SocketError, Errno::ECONNREFUSED, SteamCondenser::TimeoutError | |
false | |
end | |
end | |
def move_logs | |
Dir.chdir(LOGS_SRC_DIR) | |
FileUtils.mv(Dir.glob(LOGS_GLOB), LOGS_DEST_DIR, :force => true) | |
end | |
def move_stv_demos | |
Dir.chdir(STV_SRC_DIR) | |
FileUtils.mv(Dir.glob(STV_GLOB), STV_DEST_DIR, :force => true) | |
end | |
if server_empty? | |
move_logs | |
move_stv_demos | |
if COMPRESS_DEMOS | |
`#{COMPRESS_COMMAND}` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment