]> git.treefish.org Git - mtxbot.git/blobdiff - src/mtxbot.py
Fix presence shutdown
[mtxbot.git] / src / mtxbot.py
index d92dcdc2e2dd95368ee8e9ccf10a2bf87d9f470a..011341f85b7204a6674a886112729c1da503d16f 100755 (executable)
@@ -36,6 +36,9 @@ async def main():
         done, pending = await asyncio.wait( presence_tasks,
                                             return_when = asyncio.FIRST_EXCEPTION )
 
+        for presence in presences:
+            presence.stop()
+
         for task in done:
             try:
                 task.result()
@@ -43,6 +46,7 @@ async def main():
                 logging.error( "Error running task: %s" % str(e) )
 
     finally:
+        logging.info("Closing client...")
         await client.close()
 
 logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s',
@@ -51,6 +55,7 @@ logging.basicConfig(format='[%(asctime)s] %(levelname)s: %(message)s',
 
 mainPid = os.getpid()
 signal.signal(signal.SIGINT, handleInterrupt)
+signal.signal(signal.SIGTERM, handleInterrupt)
 
 stop = False
 
@@ -61,10 +66,12 @@ if len(sys.argv) != 2:
 with open(sys.argv[1]) as configFile:
     config = json.load(configFile)
 
+fifo_dir = os.getenv('MTXBOT_FIFO_DIR', '/run/mtxbot')
+
 while not stop:
     presences = []
-    for entry in os.listdir(config['paths']['fifodir']):
-        fullpath = "%s/%s" % (config['paths']['fifodir'], entry)
+    for entry in os.listdir(fifo_dir):
+        fullpath = "%s/%s" % (fifo_dir, entry)
         if stat.S_ISFIFO(os.stat(fullpath).st_mode):
             logging.info("Creating presence for %s..." % entry)
             presences.append( Presence(entry, fullpath) )