From: John Runyon Date: Sun, 18 Jun 2023 16:50:14 +0000 (-0600) Subject: fix watchdog, fix exiting when network goes away, etc X-Git-Url: https://jfr.im/git/erebus.git/commitdiff_plain/2a44c0cde516cf63e24cc43ad940c040e92dfca1?hp=958b8081997f104efffcbc6b1f7bf2981956152d fix watchdog, fix exiting when network goes away, etc --- diff --git a/bot.py b/bot.py index 157b090..6ea8128 100644 --- a/bot.py +++ b/bot.py @@ -69,7 +69,8 @@ class Bot(object): def watchdog(self): if time.time() > int(self.parent.cfg.get('watchdog', 'maxtime', default=300))+self.lastreceived: self.parse("ERROR :Fake-error from watchdog timer.") - self.watchdogtimer = MyTimer(int(self.parent.cfg.get('watchdog', 'interval', default=30)), self.watchdog) + watchdogtimer = MyTimer(int(self.parent.cfg.get('watchdog', 'interval', default=30)), self.watchdog) + watchdogtimer.start() def log(self, *args, **kwargs): self.parent.log(self.nick, *args, **kwargs) @@ -138,6 +139,7 @@ class Bot(object): self._checknick() def _goterror(self, pieces): # TODO: better handling, just reconnect that single bot + self.parent.mustquit = Exception(' '.join(pieces)) try: self.quit("Error detected: %s" % ' '.join(pieces)) except: pass @@ -145,7 +147,7 @@ class Bot(object): curs = self.parent.query("UPDATE bots SET connected = 0") curs.close() except: pass - os._exit(2) # can't use sys.exit since we might be in a sub-thread + sys.exit(2) def _got001(self, pieces): # We wait until the end of MOTD instead to consider ourselves registered, but consider uptime as of 001 self.connecttime = time.time() @@ -364,6 +366,7 @@ class Bot(object): self.msg(user, "Command failed. Code: CBEXC%09.3f" % (time.time() % 100000)) self.__debug_cbexception("hook", user=user, target=target, msg=msg) except SystemExit as e: + self.parent.mustquit = e try: curs = self.parent.query("UPDATE bots SET connected = 0") curs.close() diff --git a/erebus.py b/erebus.py index 5893cb8..4b33231 100644 --- a/erebus.py +++ b/erebus.py @@ -140,6 +140,7 @@ class Erebus(object): #singleton to pass around def __repr__(self): return "" % (self.name) def __init__(self, cfg): + self.mustquit = None self.starttime = time.time() self.cfg = cfg self.trigger = cfg.trigger @@ -223,10 +224,12 @@ class Erebus(object): #singleton to pass around return chan def poll(self): + timeout_seconds = 30 if self.potype == "poll": - return [fd for (fd, ev) in self.po.poll()] + pollres = self.po.poll(timeout_seconds * 1000) + return [fd for (fd, ev) in pollres] elif self.potype == "select": - return select.select(self.fdlist, [], [])[0] + return select.select(self.fdlist, [], [], timeout_seconds)[0] def connectall(self): for bot in self.bots.values(): @@ -329,6 +332,8 @@ def loop(): for fileno in poready: for line in main.fd(fileno).getdata(): main.fd(fileno).parse(line) + if main.mustquit is not None: + raise main.mustquit if __name__ == '__main__': try: os.rename('logfile', 'oldlogs/%s' % (time.time())) diff --git a/modules/control.py b/modules/control.py index b4dbfbf..4d5dbcc 100644 --- a/modules/control.py +++ b/modules/control.py @@ -31,7 +31,6 @@ def die(bot, user, chan, realtarget, *args): for botitem in bot.parent.bots.values(): bot.conn.send("QUIT :Restarting. %s" % (quitmsg)) sys.exit(0) - os._exit(0) @lib.hook(needchan=False, glevel=lib.MANAGER) @lib.help("", "loads a module")