# setup the context debug_mode = action == 'debug' try: from amplify.agent.common.context import context context.setup(app='agent', config_file=options.config, pid_file=options.pid, log_file=options.log, debug=debug_mode) except: import traceback print(traceback.format_exc(sys.exc_traceback)) # run the agent try: from amplify.agent.supervisor import Supervisor supervisor = Supervisor(foreground=options.foreground, debug=debug_mode) if options.foreground or (debug_mode and options.log): supervisor.run() else: from amplify.agent.common.runner import Runner daemon_runner = Runner(supervisor) daemon_runner.do_action() except: context.default_log.error('uncaught exception during run time', exc_info=True) print(traceback.format_exc(sys.exc_traceback))
def run(agent_name=None): """ Agent startup procedure Reads options, sets the environment, does other good things :param agent_name: str agent name """ try: from setproctitle import setproctitle proctitle = '%s-agent' % agent_name setproctitle(proctitle) except ImportError: pass try: action = sys.argv[1] if action not in ('start', 'stop', 'configtest', 'debug'): raise IndexError except IndexError: print("Invalid action or no action supplied\n") parser.print_help() sys.exit(1) # check config before start if action in ('configtest', 'debug', 'start'): wait_for_cloud = True if action == 'start' else False rc = test_configuration_and_enviroment(options.config, options.pid, wait_for_cloud, agent_name) print("") if action == 'configtest' or rc: sys.exit(rc) # setup the context debug_mode = action == 'debug' try: from amplify.agent.common.context import context context.setup(app='agent', config_file=options.config, pid_file=options.pid, log_file=options.log, debug=debug_mode, agent_name=agent_name) except: print(traceback.format_exc(sys.exc_traceback)) # run the agent try: from amplify.agent.supervisor import Supervisor supervisor = Supervisor(foreground=options.foreground, debug=debug_mode) if options.foreground or (debug_mode and options.log): supervisor.run() else: from amplify.agent.common.runner import Runner daemon_runner = Runner(supervisor) daemon_runner.do_action() except: context.default_log.error('uncaught exception during run time', exc_info=True) print(traceback.format_exc(sys.exc_traceback))
if action in ('configtest', 'start'): rc = test_config(options.config, options.pid) print("") if action == 'configtest' or rc: sys.exit(rc) try: from amplify.agent.context import context context.setup( app='agent', config_file=options.config, pid_file=options.pid ) except: import traceback print(traceback.format_exc(sys.exc_traceback)) try: from amplify.agent.supervisor import Supervisor supervisor = Supervisor(foreground=options.foreground) if not options.foreground: from amplify.agent.runner import Runner daemon_runner = Runner(supervisor) daemon_runner.do_action() else: supervisor.run() except: context.default_log.error('uncaught exception during run time', exc_info=True) print(traceback.format_exc(sys.exc_traceback))