summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFreeyorp <TheFreeYorp+git@gmail.com>2024-04-20 19:07:04 +0000
committerFreeyorp <TheFreeYorp+git@gmail.com>2024-04-20 19:07:04 +0000
commit367c1b244e0ba78bfe76c1a70d33ca066a4a99ea (patch)
tree964653c16fb85015c438d80d268c0604a134b9ce
parent934cf5c93f3a323cea85384557b408c388b0848f (diff)
downloadmanamarket-master.tar.gz
manamarket-master.tar.bz2
manamarket-master.tar.xz
manamarket-master.zip
Implement basic systemd keepalivesHEADmaster
There are greater underlying issues here. But this serves as a kludge while we're busy with fire extinguishers elsewhere.
-rwxr-xr-xmain.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/main.py b/main.py
index cd4397e..cdb3e71 100755
--- a/main.py
+++ b/main.py
@@ -46,6 +46,7 @@ import utils
import eliza
from onlineusers import SqliteDbManager
from ircbot import IRCBot
+from sdnotify import SystemdNotifier
chatbot = eliza.eliza()
shop_broadcaster = utils.Broadcast()
@@ -59,6 +60,10 @@ ItemLog = utils.ItemLog()
logger = logging.getLogger('ManaLogger')
db_manager = SqliteDbManager(config.sqlite3_dbfile)
ircbot = IRCBot()
+sd = SystemdNotifier()
+
+# How long to wait between WATCHDOG=1 systemd keepalives, in seconds
+sd_min_keepalive_rate = 5
def process_whisper(nick, msg, mapserv):
msg = filter(lambda x: x in utils.allowed_chars, msg)
@@ -854,6 +859,15 @@ def main():
ircbot.broadcastFunc = broadcast_from_irc
ircbot.start()
+ # Functionality for systemd watchdog keepalives
+ last_notify = None
+ def notify_systemd():
+ global last_sd_notify
+ sd.notify("WATCHDOG=1")
+ last_sd_notify = time.time()
+ return True
+ notify_systemd()
+
# Map server packet loop
print "Entering map packet loop\n";
while True:
@@ -862,6 +876,10 @@ def main():
break
pb.feed(data)
+ # If it's been more than five seconds since we last notified systemd that we're still alive, do so now.
+ if time.time() - last_notify > sd_min_keepalive_rate:
+ notify_systemd()
+
# For unfinished trades - one way to distrupt service would be leaving a trade active.
if trader_state.Trading.test():
if time.time() - trader_state.timer > 2*60: