Commit 661e6a4e authored by Sigmund Augdal's avatar Sigmund Augdal

Wrap the daemon main code in a try: except block and log any exceptions before...

Wrap the daemon main code in a try: except block and log any exceptions before exiting, since stderr isn't available to the daemon
parent f6541b56
......@@ -139,8 +139,12 @@ class Generator(object):
def daemon_main(args):
generator = Generator(args.etcd_host, args.cert, args.key, args.cacert, args.logfile)
generator.main()
while True:
try:
generator = Generator(args.etcd_host, args.cert, args.key, args.cacert, args.logfile)
generator.main()
except:
logging.exception("Unhandled exception")
def parse_args():
......
......@@ -222,8 +222,11 @@ class Generator(object):
def daemon_main(args):
generator = Generator(args.cert, args.key, args.cacert, args.logfile)
generator.main()
try:
generator = Generator(args.cert, args.key, args.cacert, args.logfile)
generator.main()
except:
logging.exception("Unhandled exception")
def parse_args():
......
......@@ -135,7 +135,7 @@ def daemon_main(args):
try:
main(args)
except Exception:
logging.exception("Unhandled exception. Restarting")
logging.exception("Unhandled exception")
def parse_args():
......
......@@ -57,6 +57,13 @@ def main(logfile, interface):
state = new_state
def daemon_main(args):
try:
main(args.logfile, args.interface)
except:
logging.exception("Unhandled exception")
def parse_args():
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument('-d', '--daemonize', default=False, action='store_true',
......@@ -72,8 +79,7 @@ def parse_args():
if __name__ == '__main__':
args = parse_args()
if args.daemonize:
daemon_main = lambda: main(args.logfile, args.interface)
daemon = Daemonize(app=APP, pid=args.pidfile, action=daemon_main)
daemon = Daemonize(app=APP, pid=args.pidfile, action=lambda: daemon_main(args))
daemon.start()
else:
main(None, args.interface)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment