import rpyc import time import schedule s1={'ip':'192.168.192.199','names':['poi1','poi2']} s2={'ip':'192.168.192.58','names':['poi1','poi2']} s3={'ip':'192.168.192.146','names':['poi1','poi2']} s4={'ip':'192.168.192.45','names':['poi1','poi2']} s5={'ip':'192.168.192.156','names':['hhhclick1','hhhclick2','seo1','seo2']} servers=[s1,s2,s3,s4,s5] #conn = rpyc.ssl_connect("192.168.192.199", port = 18812, keyfile="c:/tmp/client.key", # certfile="c:/tmp/client.cer") def do_job(): global servers for srv in servers: print(srv['ip']) conn = rpyc.classic.connect(srv['ip'], port = 18812) ros=conn.modules.os conn.execute('import docker') rdocker=conn.modules.docker client = rdocker.from_env() lst=client.containers.list() cur_names=[] for l in lst: cur_names.append(l.name) for n in srv['names']: if n not in cur_names: print("calling: " +n) ros.system('docker container restart '+n) do_job() schedule.every(3).minutes.do(do_job) while True: schedule.run_pending() time.sleep(1)