def proxy_main(args, opts): assert opts.thermos_json and os.path.exists(opts.thermos_json) assert opts.sandbox assert opts.checkpoint_root thermos_task = get_task_from_options(opts) prebound_ports = opts.prebound_ports missing_ports = set(thermos_task.ports()) - set(prebound_ports) if missing_ports: app.error('ERROR! Unbound ports: %s' % ' '.join(port for port in missing_ports)) task_runner = TaskRunner(thermos_task.task, opts.checkpoint_root, opts.sandbox, task_id=opts.task_id, user=opts.setuid, portmap=prebound_ports, chroot=opts.chroot, planner_class=CappedTaskPlanner) for sig in (signal.SIGUSR1, signal.SIGUSR2): signal.signal(sig, functools.partial(runner_teardown, task_runner)) try: task_runner.run() except TaskRunner.InternalError as err: app.error('Internal error: %s' % err) except TaskRunner.InvalidTask as err: app.error(str(err)) except TaskRunner.StateError: app.error('Task appears to already be in a terminal state.') except KeyboardInterrupt: runner_teardown(task_runner)
def _really_run(task, root, sandbox, task_id=None, user=None, prebound_ports=None, chroot=None, daemon=False): prebound_ports = prebound_ports or {} missing_ports = set(task.ports()) - set(prebound_ports.keys()) if missing_ports: app.error('ERROR! Unbound ports: %s' % ' '.join(port for port in missing_ports)) task_runner = TaskRunner(task.task, root, sandbox, task_id=task_id, user=user, portmap=prebound_ports, chroot=chroot) if daemon: print('Daemonizing and starting runner.') try: log.teardown_stderr_logging() daemonize() except Exception as e: print("Failed to daemonize: %s" % e) sys.exit(1) try: task_runner.run() except KeyboardInterrupt: print('Got keyboard interrupt, killing job!') task_runner.close_ckpt() task_runner.kill()