From ad85a0cee37ee0ac1014927f6a0defe31c1691dd Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 15 May 2017 17:05:22 +0800 Subject: [PATCH] add session manager (#691) --- artiq/frontend/artiq_master.py | 2 +- artiq/frontend/artiq_session.py | 52 ++++++++++++++++++++++++++++++++ doc/manual/management_system.rst | 4 +++ setup.py | 1 + 4 files changed, 58 insertions(+), 1 deletion(-) create mode 100755 artiq/frontend/artiq_session.py diff --git a/artiq/frontend/artiq_master.py b/artiq/frontend/artiq_master.py index 5513537c0..47d421ce2 100755 --- a/artiq/frontend/artiq_master.py +++ b/artiq/frontend/artiq_master.py @@ -134,7 +134,7 @@ def main(): bind, args.port_logging)) atexit_register_coroutine(server_logging.stop) - logger.info("running, bound to %s", bind) + print("ARTIQ master is now ready.") loop.run_forever() if __name__ == "__main__": diff --git a/artiq/frontend/artiq_session.py b/artiq/frontend/artiq_session.py new file mode 100755 index 000000000..b04a83008 --- /dev/null +++ b/artiq/frontend/artiq_session.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python3 + +import argparse +import sys +import subprocess + + + +def get_argparser(): + parser = argparse.ArgumentParser( + description="ARTIQ session manager. " + "Automatically runs the master, dashboard and " + "local controller manager on the current machine.") + parser.add_argument("-m", action="append", default=[], + help="add argument to the master command line") + parser.add_argument("-d", action="append", default=[], + help="add argument to the dashboard command line") + parser.add_argument("-c", action="append", default=[], + help="add argument to the controller manager command line") + return parser + + +def main(): + args = get_argparser().parse_args() + + master_cmd = [sys.executable, "-u", "-m", "artiq.frontend.artiq_master"] + dashboard_cmd = [sys.executable, "-m", "artiq.frontend.artiq_dashboard"] + ctlmgr_cmd = [sys.executable, "-m", "artiq.frontend.artiq_ctlmgr"] + master_cmd += args.m + dashboard_cmd += args.d + ctlmgr_cmd += args.c + + with subprocess.Popen(master_cmd, + stdout=subprocess.PIPE, universal_newlines=True, + bufsize=1) as master: + master_ready = False + for line in iter(master.stdout.readline, ""): + sys.stdout.write(line) + if line.rstrip() == "ARTIQ master is now ready.": + master_ready = True + break + if master_ready: + with subprocess.Popen(dashboard_cmd): + with subprocess.Popen(ctlmgr_cmd): + for line in iter(master.stdout.readline, ""): + sys.stdout.write(line) + else: + print("session: master failed to start, exiting.") + + +if __name__ == "__main__": + main() diff --git a/doc/manual/management_system.rst b/doc/manual/management_system.rst index c28e612cf..cd771b226 100644 --- a/doc/manual/management_system.rst +++ b/doc/manual/management_system.rst @@ -154,3 +154,7 @@ Front-end tool reference .. argparse:: :ref: artiq.frontend.artiq_dashboard.get_argparser :prog: artiq_dashboard + +.. argparse:: + :ref: artiq.frontend.artiq_session.get_argparser + :prog: artiq_session diff --git a/setup.py b/setup.py index 12c6b4238..c8001e8f5 100755 --- a/setup.py +++ b/setup.py @@ -31,6 +31,7 @@ console_scripts = [ "artiq_influxdb=artiq.frontend.artiq_influxdb:main", "artiq_master=artiq.frontend.artiq_master:main", "artiq_mkfs=artiq.frontend.artiq_mkfs:main", + "artiq_session=artiq.frontend.artiq_session:main", "artiq_rpctool=artiq.frontend.artiq_rpctool:main", "artiq_run=artiq.frontend.artiq_run:main", "artiq_flash=artiq.frontend.artiq_flash:main",