Updating linux actor

This commit is contained in:
Adolfo Gómez 2014-05-24 02:30:18 +00:00
parent 9bdfb4a7eb
commit c479fc3fbd
2 changed files with 26 additions and 23 deletions

View File

@ -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)

View File

@ -6,7 +6,7 @@ timeout=5
[logging]
debug=DEBUG
debug=INFO
log=/var/log/udsactor.log
# Size in megas
maxsize=20