.BANCHO. Add ir command, more info in system status
This commit is contained in:
parent
771b6e294b
commit
a1d45a4419
|
@ -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
|
||||
"""
|
||||
|
||||
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):
|
||||
if message[0] == "rules":
|
||||
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()
|
||||
|
||||
# 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 += "\n"
|
||||
msg += "=== BANCHO STATS ===\n"
|
||||
msg += "Connected users: {}\n".format(data["connectedUsers"])
|
||||
msg += "Multiplayer matches: {}\n".format(data["matches"])
|
||||
msg += "Uptime: {}\n".format(data["uptime"])
|
||||
msg += "\n"
|
||||
msg += "=== SYSTEM STATS ===\n"
|
||||
msg += "CPU: {}%\n".format(data["cpuUsage"])
|
||||
|
@ -724,6 +730,10 @@ commands = [
|
|||
}, {
|
||||
"trigger": "!last",
|
||||
"callback": tillerinoLast
|
||||
}, {
|
||||
"trigger": "!ir",
|
||||
"privileges": privileges.ADMIN_MANAGE_SERVERS,
|
||||
"callback": instantRestart
|
||||
}
|
||||
#
|
||||
# "trigger": "!acc",
|
||||
|
|
|
@ -6,6 +6,8 @@ import sys
|
|||
import threading
|
||||
import signal
|
||||
from helpers import logHelper as log
|
||||
import time
|
||||
import math
|
||||
|
||||
def runningUnderUnix():
|
||||
"""
|
||||
|
@ -17,7 +19,7 @@ def runningUnderUnix():
|
|||
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
|
||||
|
||||
|
@ -27,7 +29,7 @@ def scheduleShutdown(sendRestartTime, restart, message = ""):
|
|||
"""
|
||||
|
||||
# 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))
|
||||
|
||||
# Send notification if set
|
||||
|
@ -35,7 +37,7 @@ def scheduleShutdown(sendRestartTime, restart, message = ""):
|
|||
glob.tokens.enqueueAll(serverPackets.notification(message))
|
||||
|
||||
# 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
|
||||
|
||||
# Restart/shutdown
|
||||
|
@ -44,8 +46,8 @@ def scheduleShutdown(sendRestartTime, restart, message = ""):
|
|||
else:
|
||||
action = shutdownServer
|
||||
|
||||
# Schedule actual server shutdown/restart 20 seconds after server restart packet, so everyone gets it
|
||||
threading.Timer(sendRestartTime+20, action).start()
|
||||
# Schedule actual server shutdown/restart some seconds after server restart packet, so everyone gets it
|
||||
threading.Timer(sendRestartTime+delay, action).start()
|
||||
|
||||
|
||||
def restartServer():
|
||||
|
@ -56,7 +58,7 @@ def restartServer():
|
|||
|
||||
def shutdownServer():
|
||||
"""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
|
||||
os.kill(os.getpid(), sig)
|
||||
|
||||
|
@ -76,9 +78,23 @@ def getSystemInfo():
|
|||
# General stats
|
||||
data["connectedUsers"] = len(glob.tokens.tokens)
|
||||
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["totalMemory"] = "{0:.2f}".format(psutil.virtual_memory()[0]/1074000000)
|
||||
data["usedMemory"] = "{0:.2f}".format(psutil.virtual_memory()[3]/1074000000)
|
||||
memory = psutil.virtual_memory()
|
||||
data["totalMemory"] = "{0:.2f}".format(memory.total/1074000000)
|
||||
data["usedMemory"] = "{0:.2f}".format(memory.active/1074000000)
|
||||
|
||||
# Unix only stats
|
||||
if data["unix"] == True:
|
||||
|
|
|
@ -4,6 +4,7 @@ from objects import tokenList
|
|||
from objects import channelList
|
||||
from objects import matchList
|
||||
from objects import fileLocks
|
||||
import time
|
||||
|
||||
try:
|
||||
with open("version") as f:
|
||||
|
@ -32,3 +33,5 @@ discord = False
|
|||
gzip = False
|
||||
localize = False
|
||||
sentry = False
|
||||
|
||||
startTime = int(time.time())
|
||||
|
|
15
pep.py
15
pep.py
|
@ -71,6 +71,13 @@ if __name__ == "__main__":
|
|||
else:
|
||||
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
|
||||
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)
|
||||
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
|
||||
print("> Initializing chat channels... ")
|
||||
glob.channels.loadChannels()
|
||||
|
|
Loading…
Reference in New Issue
Block a user