From c479fc3fbd294c0e51f3ce4afd9550c13bc57244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adolfo=20G=C3=B3mez?= Date: Sat, 24 May 2014 02:30:18 +0000 Subject: [PATCH] Updating linux actor --- linuxActor/src/actor.py | 47 ++++++++++++++++++++----------------- linuxActor/src/udsactor.cfg | 2 +- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/linuxActor/src/actor.py b/linuxActor/src/actor.py index e43508b6..859d72d1 100644 --- a/linuxActor/src/actor.py +++ b/linuxActor/src/actor.py @@ -11,7 +11,7 @@ from uds.actor.daemon import Daemon from uds.actor.rpc import Rpc from uds.actor import net from uds.actor.renamer import rename - + logger = logging.getLogger('uds') class MyDaemon(Daemon): @@ -24,18 +24,18 @@ class MyDaemon(Daemon): time.sleep(4) # Now, get info of what to do Rpc.initialize() - + # waits for a valid command (maybe broker down or not reachable, so we loop here till we know what to do (that is, broker is reachable)) - todo = None - while todo is None: + todo = None + while todo is None: Rpc.resetId() todo = Rpc.getInfo() if todo is None: time.sleep(4) - - # We can get 'rename:newname', ''. Anything else is an error + + # We can get 'rename:newname', ''. Anything else is an error data = todo.split(':') - + if data[0] == 'rename': logger.info('Renaming to {0}'.format(data[1])) rename(data[1]) @@ -48,24 +48,27 @@ class MyDaemon(Daemon): # Error, log and exit logger.error('Unknown command received: {0}'.format(todo)) return - + # Keep notifiyin ip changes info = net.getExternalIpAndMacs() # We have "info" with know interfaces while True: - newInfo = net.getExternalIpAndMacs() - for k in info.keys(): - if info[k]['ip'] != newInfo[k]['ip']: - if Rpc.notifyIpChange() is not None: - info = newInfo - else: - logger.info('Could not notify IP address. Will retry later.') - break - time.sleep(5) + try: + newInfo = net.getExternalIpAndMacs() + for k in info.keys(): + if info[k]['ip'] != newInfo[k]['ip']: + if Rpc.notifyIpChange() is not None: + info = newInfo + else: + logger.info('Could not notify IP address. Will retry later.') + break + time.sleep(5) + except: + logger.exception('Exception caught at main loop!') return - -if __name__ == '__main__': + +if __name__ == '__main__': if len(sys.argv) == 3: if 'login' == sys.argv[1]: logger.debug('Notifiyin login') @@ -77,9 +80,9 @@ if __name__ == '__main__': Rpc.initialize() Rpc.logout(sys.argv[2]) sys.exit(0) - + logger.debug('Executing actor') - daemon = MyDaemon('/var/run/udsactor.pid') + daemon = MyDaemon('/var/run/udsactor.pid') if len(sys.argv) == 2: if 'start' == sys.argv[1]: daemon.start() @@ -93,5 +96,5 @@ if __name__ == '__main__': sys.exit(0) else: print "usage: %s start|stop|restart|login 'username'|logout 'username'" % sys.argv[0] - sys.exit(2) + sys.exit(2) diff --git a/linuxActor/src/udsactor.cfg b/linuxActor/src/udsactor.cfg index 4bb19900..caf587e2 100644 --- a/linuxActor/src/udsactor.cfg +++ b/linuxActor/src/udsactor.cfg @@ -6,7 +6,7 @@ timeout=5 [logging] -debug=DEBUG +debug=INFO log=/var/log/udsactor.log # Size in megas maxsize=20