comparison bot.py @ 121:765e460bc20a

Restart all bridges connected to a MUC server when it goes down Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Wed, 13 Jan 2010 11:06:20 +0100
parents ae55fc0d783d
children 9e90e15913a7
comparison
equal deleted inserted replaced
120:de00bbe026a7 121:765e460bc20a
147 # considering this lack of semantic we have no choice but to do a check on the reason 147 # considering this lack of semantic we have no choice but to do a check on the reason
148 reason = d.getTag('reason') 148 reason = d.getTag('reason')
149 if reason: 149 if reason:
150 r = reason.getData() 150 r = reason.getData()
151 if r == 'The conference component is shutting down': 151 if r == 'The conference component is shutting down':
152 # MUC server is going down, try to restart the bridge in 1 minute 152 # MUC server is going down, try to restart the bridges in 1 minute
153 self.error('[Warning] The MUC server '+from_.getDomain()+' seems to be going down, the bot will try to recreate the bridge '+str(bridge)+' in 1 minute', send_to_admins=True) 153 bridges = self.findBridges([from_.getDomain()])
154 bridge.stop(message='MUC server seems to be going down, will try to recreate the bridge in 1 minute') 154 error_message = '[Warning] The MUC server '+from_.getDomain()+' seems to be going down, the bot will try to recreate all bridges related to this server in 1 minute'
155 self.irc.execute_delayed(60, bridge.init2) 155 self.restart_bridges_delayed(bridges, 60, error_message)
156 self.error(presence.__str__(fancy=1).encode('utf-8'), debug=True)
156 return 157 return
157 elif r == '': 158 elif r == '':
158 r = 'None given' 159 r = 'None given'
159 else: 160 else:
160 r = 'None given' 161 r = 'None given'
256 for c in error.getChildren(): 257 for c in error.getChildren():
257 if c.getNamespace() == 'urn:ietf:params:xml:ns:xmpp-stanzas' and c.getName() != 'text': 258 if c.getNamespace() == 'urn:ietf:params:xml:ns:xmpp-stanzas' and c.getName() != 'text':
258 err = error.getAttr('type')+' '+c.getName() 259 err = error.getAttr('type')+' '+c.getName()
259 if err == 'cancel remote-server-not-found': 260 if err == 'cancel remote-server-not-found':
260 # Remote server not found 261 # Remote server not found
261 error_message = '[Error] XMPP Remote server not found: '+from_.getDomain()
262
263 # Stop bridges that depend on this server 262 # Stop bridges that depend on this server
264 bridges = self.findBridges([from_.getDomain()]) 263 bridges = self.findBridges([from_.getDomain()])
265 if len(bridges) > 0: 264 error_message = '[Error] XMPP Remote server not found: '+from_.getDomain()
266 error_message += '\nThese bridges will be stopped:' 265 self.restart_bridges_delayed(bridges, 60, error_message)
267 for b in bridges:
268 error_message += '\n'+str(b)
269 if hasattr(b, 'reconnecting'):
270 leave_message = 'MUC server seems to be down'
271 else:
272 leave_message = 'MUC server seems to be down, will try to recreate the bridge in 1 minute'
273 self.reconnecting = True
274 self.irc.execute_delayed(60, b.init2)
275 b.stop(message=leave_message)
276
277 self.error(error_message, send_to_admins=True)
278 self.error(presence.__str__(fancy=1).encode('utf-8'), debug=True) 266 self.error(presence.__str__(fancy=1).encode('utf-8'), debug=True)
279 else: 267 else:
280 raise Exception(presence.__str__(fancy=1).encode('utf-8')) 268 raise Exception(presence.__str__(fancy=1).encode('utf-8'))
281 269
282 elif resource != bridge.bot.nickname: 270 elif resource != bridge.bot.nickname:
984 b.init2() 972 b.init2()
985 973
986 self.error('Bot restarted.', send_to_admins=True) 974 self.error('Bot restarted.', send_to_admins=True)
987 975
988 976
977 def restart_bridges_delayed(self, bridges, delay, error_message):
978 if len(bridges) > 0:
979 error_message += '\nThese bridges will be stopped:'
980 for b in bridges:
981 error_message += '\n'+str(b)
982 if hasattr(b, 'reconnecting'):
983 leave_message = 'MUC server seems to be down'
984 else:
985 leave_message = 'MUC server seems to be down, will try to recreate the bridge in '+str(delay)+' seconds'
986 self.reconnecting = True
987 self.irc.execute_delayed(delay, b.init2)
988 b.stop(message=leave_message)
989
990 self.error(error_message, send_to_admins=True)
991
992
989 def __del__(self): 993 def __del__(self):
990 for bridge in self.bridges: 994 for bridge in self.bridges:
991 self.removeBridge(bridge) 995 self.removeBridge(bridge)