使用paramiko重启rpyc

时间:2016-09-08 16:27:09

标签: python linux paramiko rpyc

我需要使用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实际上已经被杀死但是它没有再次启动...... 我做错了什么?

0 个答案:

没有答案