diff options
author | Freeyorp <TheFreeYorp+git@gmail.com> | 2024-04-20 19:07:04 +0000 |
---|---|---|
committer | Freeyorp <TheFreeYorp+git@gmail.com> | 2024-04-20 19:07:04 +0000 |
commit | 367c1b244e0ba78bfe76c1a70d33ca066a4a99ea (patch) | |
tree | 964653c16fb85015c438d80d268c0604a134b9ce | |
parent | 934cf5c93f3a323cea85384557b408c388b0848f (diff) | |
download | manamarket-367c1b244e0ba78bfe76c1a70d33ca066a4a99ea.tar.gz manamarket-367c1b244e0ba78bfe76c1a70d33ca066a4a99ea.tar.bz2 manamarket-367c1b244e0ba78bfe76c1a70d33ca066a4a99ea.tar.xz manamarket-367c1b244e0ba78bfe76c1a70d33ca066a4a99ea.zip |
There are greater underlying issues here. But this serves as a kludge while
we're busy with fire extinguishers elsewhere.
-rwxr-xr-x | main.py | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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: |