def check_bot(self, botname, port, path, user):
bot = botname
if not botname in data:
addlog('starting '+ botname)
os.chdir(path)
proc = subprocess.Popen('screen -dmS "'+ botname +'" su '+ user +' -c "bash launch.sh -P '+ str(port) +'"',shell=True).wait()
addlog(botname + ' has been successfully started')
print(colored(botname + ' has been successfully started\n',"blue"))
spid = screen_pid(botname)
data[botname] = {"pid": spid}
time.sleep(5)
while True:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(5.0)
s.connect(('localhost', int(port)))
s.shutdown(socket.SHUT_WR)
s.close()
except:
try:
os.kill(int(data[botname][pid]), 9)
except Exception as e:
a = 'a'
wipe = subprocess.Popen(["screen", "-wipe"], stdout=subprocess.PIPE)
del data[botname]
addlog(botname + ' was crashed and it has been successfully restarted.')
print(botname + ' was crashed and it has been successfully restarted.')
botname = bot+get_random_key(2)
proc = subprocess.Popen('screen -dmS "'+ botname +'" su '+ user +' -c "bash launch.sh -P '+ str(port) +'"',shell=True).wait()
spid = screen_pid(botname)
data[botname] = {"pid": spid}
time.sleep(15)
评论列表
文章目录