1

我需要使用 paramiko 在远程机器上重新启动 rpyc。我试过做:

import paramiko
import rpyc
import time


def get_session(ip):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(ip, username='xxxx', password='xxxxxx', timeout=150.0)

    session = ssh.get_transport().open_session()
    session.get_pty()
    session.set_combine_stderr(True)

    return ssh, session

def exec_command(session, cmd):
    session.exec_command(cmd)
    stdout = session.makefile('rb')

    for line in stdout.readlines():
            print line

def try_rpyc_connect(ip):
    c = rpyc.classic.connect(ip)

if __name__ == "__main__":
    ssh, session = get_session('a whole new world')
    exec_command(session, 'killall -9 rpyc_classic.py')
    # get new session because the last one is gone now...
    ssh, session = get_session('a whole new world')
    exec_command(session, 'rpyc_classic.py &')
    time.sleep(2)
    try_rpyc_connect('a whole new world')

我看到 rpyc 实际上已被杀死,但它没有再次启动......我做错了什么?

4

0 回答 0