1

I need to restart the rpyc on a remote machine using paramiko. I've tried doing:

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')

I see that rpyc is in fact killed but it is not started again... What am I doing wrong?

Bob Sacamano
  • 699
  • 15
  • 39

0 Answers0