Exemplo n.º 1
0
def cmd_stop_env():
    """
    stop docker container
    """
    assert_conf()
    root = conf

    if is_running_in_docker():
        do_stop_docker()
        for c in root.iterfind("docker/stop_cmd"):
            run_in_container(c.text)

    for c in root.iterfind("stop_cmd"):
        cmd(c.text, _log=logger)
Exemplo n.º 2
0
def run_in_container(a_cmd, _interactive=False, _detached=False):
    """execute a system command possibly inside the docker container

    :param a_cmd:
    :param _interactive:  (Default value = False)

    """
    if is_running_in_docker():
        opts = "-ti" if _interactive else "-t"
        container_name = get_container_name()
        if not container_name:
            raise CommandError(
                "No docker container name defined in qdeploy.conf")

        container_exec = ["docker", "exec", opts, container_name]
        if isinstance(a_cmd, str):
            a_cmd = shlex.split(a_cmd)
        cmd_to_execute = container_exec + a_cmd
    else:
        cmd_to_execute = a_cmd

    res = cmd(cmd_to_execute, _log=logger, _detached=_detached)
    if _detached:
        res.wait()

    res.print_on_error()
    return res
Exemplo n.º 3
0
def do_stop_docker():
    """stop docker container by calling the .qdeploy/stop_docker.sh
    script
    """
    os.chdir(QDEPLOY_RESOURCES_DIR)
    container_name = get_container_name()
    if not container_name:
        raise CommandError("No docker container name defined in qdeploy.conf")

    res = cmd("./stop_docker.sh {container}",
              container=container_name,
              _log=logger)
    res.print_on_error()
    print(res.out)
Exemplo n.º 4
0
def do_start_docker():
    """start docker container by calling the .qdeploy/start_docker.sh
    script
    """
    mounts = ""
    use_x11 = "false"

    root = conf
    container_name = get_container_name()
    if not container_name:
        raise CommandError("No docker container name defined in qdeploy.conf")

    for m in root.iterfind("docker/mount"):
        mount = m.text if ":" in m.text else m.text + ":" + m.text
        mounts += " -v " + mount

    x11_node = root.find("docker/x11")
    if x11_node is not None:
        use_x11 = x11_node.text

    res = cmd(["./start_docker.sh", container_name, use_x11, mounts],
              _log=logger,
              _cwd=QDEPLOY_RESOURCES_DIR)
    res.exit_on_error()