.BANCHO. Add ir command, more info in system status

This commit is contained in:
Nyo 2016-08-28 17:25:47 +02:00
parent 771b6e294b
commit a1d45a4419
4 changed files with 45 additions and 17 deletions

View File

@ -27,6 +27,11 @@ message -- list containing arguments passed from the message
return the message or **False** if there's no response by the bot return the message or **False** if there's no response by the bot
""" """
def instantRestart(fro, chan, message):
glob.tokens.enqueueAll(serverPackets.notification("We are restarting Bancho. Be right back!"))
systemHelper.scheduleShutdown(0, True, delay=1)
return False
def faq(fro, chan, message): def faq(fro, chan, message):
if message[0] == "rules": if message[0] == "rules":
return "Please make sure to check (Ripple's rules)[http://ripple.moe/?p=23]." return "Please make sure to check (Ripple's rules)[http://ripple.moe/?p=23]."
@ -352,12 +357,13 @@ def systemStatus(fro, chan, message):
data = systemHelper.getSystemInfo() data = systemHelper.getSystemInfo()
# Final message # Final message
msg = "pep.py bancho server v{}".format(glob.VERSION) msg = "pep.py bancho server v{}\n".format(glob.VERSION)
msg += "made by the Ripple team\n" msg += "made by the Ripple team\n"
msg += "\n" msg += "\n"
msg += "=== BANCHO STATS ===\n" msg += "=== BANCHO STATS ===\n"
msg += "Connected users: {}\n".format(data["connectedUsers"]) msg += "Connected users: {}\n".format(data["connectedUsers"])
msg += "Multiplayer matches: {}\n".format(data["matches"]) msg += "Multiplayer matches: {}\n".format(data["matches"])
msg += "Uptime: {}\n".format(data["uptime"])
msg += "\n" msg += "\n"
msg += "=== SYSTEM STATS ===\n" msg += "=== SYSTEM STATS ===\n"
msg += "CPU: {}%\n".format(data["cpuUsage"]) msg += "CPU: {}%\n".format(data["cpuUsage"])
@ -724,6 +730,10 @@ commands = [
}, { }, {
"trigger": "!last", "trigger": "!last",
"callback": tillerinoLast "callback": tillerinoLast
}, {
"trigger": "!ir",
"privileges": privileges.ADMIN_MANAGE_SERVERS,
"callback": instantRestart
} }
# #
# "trigger": "!acc", # "trigger": "!acc",

View File

@ -6,6 +6,8 @@ import sys
import threading import threading
import signal import signal
from helpers import logHelper as log from helpers import logHelper as log
import time
import math
def runningUnderUnix(): def runningUnderUnix():
""" """
@ -17,7 +19,7 @@ def runningUnderUnix():
return True if os.name == "posix" else False return True if os.name == "posix" else False
def scheduleShutdown(sendRestartTime, restart, message = ""): def scheduleShutdown(sendRestartTime, restart, message = "", delay=20):
""" """
Schedule a server shutdown/restart Schedule a server shutdown/restart
@ -27,7 +29,7 @@ def scheduleShutdown(sendRestartTime, restart, message = ""):
""" """
# Console output # Console output
log.info("Pep.py will {} in {} seconds!".format("restart" if restart else "shutdown", sendRestartTime+20)) log.info("Pep.py will {} in {} seconds!".format("restart" if restart else "shutdown", sendRestartTime+delay))
log.info("Sending server restart packets in {} seconds...".format(sendRestartTime)) log.info("Sending server restart packets in {} seconds...".format(sendRestartTime))
# Send notification if set # Send notification if set
@ -35,7 +37,7 @@ def scheduleShutdown(sendRestartTime, restart, message = ""):
glob.tokens.enqueueAll(serverPackets.notification(message)) glob.tokens.enqueueAll(serverPackets.notification(message))
# Schedule server restart packet # Schedule server restart packet
threading.Timer(sendRestartTime, glob.tokens.enqueueAll, [serverPackets.banchoRestart(50000)]).start() threading.Timer(sendRestartTime, glob.tokens.enqueueAll, [serverPackets.banchoRestart(delay*2*1000)]).start()
glob.restarting = True glob.restarting = True
# Restart/shutdown # Restart/shutdown
@ -44,8 +46,8 @@ def scheduleShutdown(sendRestartTime, restart, message = ""):
else: else:
action = shutdownServer action = shutdownServer
# Schedule actual server shutdown/restart 20 seconds after server restart packet, so everyone gets it # Schedule actual server shutdown/restart some seconds after server restart packet, so everyone gets it
threading.Timer(sendRestartTime+20, action).start() threading.Timer(sendRestartTime+delay, action).start()
def restartServer(): def restartServer():
@ -56,7 +58,7 @@ def restartServer():
def shutdownServer(): def shutdownServer():
"""Shutdown pep.py""" """Shutdown pep.py"""
log.info("> Shutting down pep.py...") log.info("Shutting down pep.py...")
sig = signal.SIGKILL if runningUnderUnix() else signal.CTRL_C_EVENT sig = signal.SIGKILL if runningUnderUnix() else signal.CTRL_C_EVENT
os.kill(os.getpid(), sig) os.kill(os.getpid(), sig)
@ -76,9 +78,23 @@ def getSystemInfo():
# General stats # General stats
data["connectedUsers"] = len(glob.tokens.tokens) data["connectedUsers"] = len(glob.tokens.tokens)
data["matches"] = len(glob.matches.matches) data["matches"] = len(glob.matches.matches)
delta = time.time()-glob.startTime
days = math.floor(delta/86400)
delta -= days*86400
hours = math.floor(delta/3600)
delta -= hours*3600
minutes = math.floor(delta/60)
delta -= minutes*60
seconds = math.floor(delta)
data["uptime"] = "{}d {}h {}m {}s".format(days, hours, minutes, seconds)
data["cpuUsage"] = psutil.cpu_percent() data["cpuUsage"] = psutil.cpu_percent()
data["totalMemory"] = "{0:.2f}".format(psutil.virtual_memory()[0]/1074000000) memory = psutil.virtual_memory()
data["usedMemory"] = "{0:.2f}".format(psutil.virtual_memory()[3]/1074000000) data["totalMemory"] = "{0:.2f}".format(memory.total/1074000000)
data["usedMemory"] = "{0:.2f}".format(memory.active/1074000000)
# Unix only stats # Unix only stats
if data["unix"] == True: if data["unix"] == True:

View File

@ -4,6 +4,7 @@ from objects import tokenList
from objects import channelList from objects import channelList
from objects import matchList from objects import matchList
from objects import fileLocks from objects import fileLocks
import time
try: try:
with open("version") as f: with open("version") as f:
@ -32,3 +33,5 @@ discord = False
gzip = False gzip = False
localize = False localize = False
sentry = False sentry = False
startTime = int(time.time())

15
pep.py
View File

@ -71,6 +71,13 @@ if __name__ == "__main__":
else: else:
consoleHelper.printDone() consoleHelper.printDone()
# Create data folder if needed
consoleHelper.printNoNl("> Checking folders... ")
paths = [".data"]
for i in paths:
if not os.path.exists(i):
os.makedirs(i, 0o770)
consoleHelper.printDone()
# Connect to db # Connect to db
try: try:
@ -108,14 +115,6 @@ if __name__ == "__main__":
consoleHelper.printColored("[!] Error while loading chat filters. Make sure there is a filters.txt file present", bcolors.RED) consoleHelper.printColored("[!] Error while loading chat filters. Make sure there is a filters.txt file present", bcolors.RED)
raise raise
# Create data folder if needed
consoleHelper.printNoNl("> Checking folders... ")
paths = [".data"]
for i in paths:
if not os.path.exists(i):
os.makedirs(i, 0o770)
consoleHelper.printDone()
# Initialize chat channels # Initialize chat channels
print("> Initializing chat channels... ") print("> Initializing chat channels... ")
glob.channels.loadChannels() glob.channels.loadChannels()