import rpyc import time import schedule s1={'ip':'192.168.192.199','names':['poi1','poi2','poi3']} #MBA_HOME #s2={'ip':'192.168.192.58','names':['poi1','poi2','poi3']} #RDP_HOME s3={'ip':'192.168.192.146','names':['poi1','poi2']} #TOSHIBA s4={'ip':'192.168.192.45','names':['poi1','poi2']} #public1 #s5={'ip':'192.168.192.156','names':['seo1','seo2']} #32g s5={'ip':'192.168.192.156','names':['poi1','poi2','poi3','poi4','poi5']} #32g #s5={'ip':'192.168.192.156','names':['hhhclick1','hhhclick2','seo1','seo2']} s6={'ip':'192.168.192.9','names':['poi1','poi2','poi3','poi4','poi5','poi6','poi7','poi8','poi9','poi10','poi11','poi12','poi13','poi14']} #64G s7={'ip':'192.168.192.139','names':['poi1','poi2','poi3','poi4','poi5','poi6','poi7','poi8','poi9','poi10','poi11','poi12','poi13','poi14','poi15','poi16']} #alston1 s8={'ip':'192.168.192.43','names':['poi1','poi2','poi3','poi4','poi5','poi6','poi7','poi8','poi9','poi10','poi11','poi12','poi13','poi14']} #alston2 #servers=[s1,s2,s4,s5,s6] servers=[s1,s5,s3,s6,s7,s8] #servers=[s1,s2,s3,s4,s5,s6] #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 cnt=0 for srv in servers: print(srv['ip']) conn=None try: conn = rpyc.classic.connect(srv['ip'], port = 18812) except: print('exception') continue 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) else: cnt+=1 print('cnt='+str(cnt)) do_job() schedule.every(3).minutes.do(do_job) while True: schedule.run_pending() time.sleep(1)