def launch_ssh_cloudflared(password='', verbose=False, prevent_interrupt=False, kill_other_processes=False):
    if kill_other_processes:
        os.system("kill -9 $(ps aux | grep 'cloudflared' | awk '{print $2}')")
    if (not os.path.isfile('cloudflared')):
        run_command('wget -q -nc https://bin.equinox.io/c/VdrWdbjqyF/cloudflared-stable-linux-amd64.tgz')
        run_command('tar zxf cloudflared-stable-linux-amd64.tgz')
    elif verbose:
        print('DEBUG: Skipping cloudflared installation')
    deb_install('openssh-server', verbose=verbose)
    run_with_pipe('echo root:{} | chpasswd'.format(password))
    run_command('mkdir -p /var/run/sshd')
    os.system("echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config")
    if password:
        os.system('echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config')
    expose_env_variable('LD_LIBRARY_PATH')
    expose_env_variable('COLAB_TPU_ADDR')
    expose_env_variable('COLAB_GPU')
    expose_env_variable('TBE_CREDS_ADDR')
    expose_env_variable('TF_FORCE_GPU_ALLOW_GROWTH')
    expose_env_variable('TPU_NAME')
    expose_env_variable('XRT_TPU_CONFIG')
    os.system('service ssh start')
    extra_params = []
    info = None
    popen_command = f"./cloudflared tunnel --url ssh://localhost:22 --logfile ./cloudflared.log --metrics localhost:45678 {' '.join(extra_params)}"
    preexec_fn = None
    if prevent_interrupt:
        popen_command = ('nohup ' + popen_command)
        preexec_fn = os.setpgrp
    popen_command = shlex.split(popen_command)
    sleep_time = 2.0
    for i in range(10):
        proc = Popen(popen_command, stdout=PIPE, preexec_fn=preexec_fn)
        if verbose:
            print(f'DEBUG: Cloudflared process: PID={proc.pid}')
        time.sleep(sleep_time)
        try:
            info = get_argo_tunnel_config()
            break
        except Exception as e:
            os.kill(proc.pid, signal.SIGKILL)
            if verbose:
                print(f'DEBUG: Exception: {e.args[0]}')
                print(f'DEBUG: Killing {proc.pid}. Retrying...')
        sleep_time *= 1.5
    if verbose:
        print('DEBUG:', info)
    if info:
        return info
    else:
        print(proc.stdout.readlines())
        raise Exception('It looks like something went wrong, please make sure your token is valid')
    proc.stdout.close()
def launch_ssh_cloudflared(password=, verbose=False, prevent_interrupt=False, kill_other_processes=False):
    if kill_other_processes:
        os.system("kill -9 $(ps aux | grep 'cloudflared' | awk '{print $2}')")
    if (not os.path.isfile('cloudflared')):
        run_command('wget -q -nc https://bin.equinox.io/c/VdrWdbjqyF/cloudflared-stable-linux-amd64.tgz')
        run_command('tar zxf cloudflared-stable-linux-amd64.tgz')
    elif verbose:
        print('DEBUG: Skipping cloudflared installation')
    deb_install('openssh-server', verbose=verbose)
    run_with_pipe('echo root:{} | chpasswd'.format(password))
    run_command('mkdir -p /var/run/sshd')
    os.system("echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config")
    if password:
        os.system('echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config')
    expose_env_variable('LD_LIBRARY_PATH')
    expose_env_variable('COLAB_TPU_ADDR')
    expose_env_variable('COLAB_GPU')
    expose_env_variable('TBE_CREDS_ADDR')
    expose_env_variable('TF_FORCE_GPU_ALLOW_GROWTH')
    expose_env_variable('TPU_NAME')
    expose_env_variable('XRT_TPU_CONFIG')
    os.system('service ssh start')
    extra_params = []
    info = None
    popen_command = f"./cloudflared tunnel --url ssh://localhost:22 --logfile ./cloudflared.log --metrics localhost:45678 {' '.join(extra_params)}"
    preexec_fn = None
    if prevent_interrupt:
        popen_command = ('nohup ' + popen_command)
        preexec_fn = os.setpgrp
    popen_command = shlex.split(popen_command)
    sleep_time = 2.0
    for i in range(10):
        proc = Popen(popen_command, stdout=PIPE, preexec_fn=preexec_fn)
        if verbose:
            print(f'DEBUG: Cloudflared process: PID={proc.pid}')
        time.sleep(sleep_time)
        try:
            info = get_argo_tunnel_config()
            break
        except Exception as e:
            os.kill(proc.pid, signal.SIGKILL)
            if verbose:
                print(f'DEBUG: Exception: {e.args[0]}')
                print(f'DEBUG: Killing {proc.pid}. Retrying...')
        sleep_time *= 1.5
    if verbose:
        print('DEBUG:', info)
    if info:
        return info
    else:
        print(proc.stdout.readlines())
        raise Exception('It looks like something went wrong, please make sure your token is valid')
    proc.stdout.close()