forward-port the noshell branch from 3.x

This commit is contained in:
computergeek125 2021-02-13 05:47:30 +00:00
parent 509c801436
commit 7b03dd3da4
2 changed files with 11 additions and 35 deletions

View File

@ -120,43 +120,19 @@ class Server:
console.info("Launching Server {} with command {}".format(self.name, self.server_command)) console.info("Launching Server {} with command {}".format(self.name, self.server_command))
if os.name == "nt": if os.name == "nt":
logger.info("Windows Detected - launching cmd") logger.info("Windows Detected")
self.server_command = self.server_command.replace('\\', '/') self.server_command = self.server_command.replace('\\', '/')
logging.info("Opening CMD prompt")
self.process = pexpect.popen_spawn.PopenSpawn('cmd \r\n', timeout=None, encoding=None)
drive_letter = self.server_path[:1]
if drive_letter.lower() != "c":
logger.info("Server is not on the C drive, changing drive letter to {}:".format(drive_letter))
self.process.send("{}:\r\n".format(drive_letter))
logging.info("changing directories to {}".format(self.server_path.replace('\\', '/')))
self.process.send('cd {} \r\n'.format(self.server_path.replace('\\', '/')))
logging.info("Sending command {} to CMD".format(self.server_command))
self.process.send(self.server_command + "\r\n")
self.is_crashed = False
else: else:
logger.info("Linux Detected - launching Bash") logger.info("Linux Detected")
self.process = pexpect.popen_spawn.PopenSpawn('/bin/bash \n', timeout=None, encoding=None)
logger.info("Changing directory to {}".format(self.server_path)) logger.info("Starting server in {p} with command: {c}".format(p=self.server_path, c=self.server_command))
self.process.send('cd {} \n'.format(self.server_path))
logger.info("Sending server start command: {} to shell".format(self.server_command))
self.process.send(self.server_command + '\n')
self.is_crashed = False self.is_crashed = False
ts = time.time() ts = time.time()
self.start_time = str(datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')) self.start_time = str(datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S'))
if psutil.pid_exists(self.process.pid): if psutil.pid_exists(self.process.pid):
parent = psutil.Process(self.process.pid) self.PID = self.process.pod
time.sleep(.5)
children = parent.children(recursive=True)
for c in children:
self.PID = c.pid
logger.info("Server {} running with PID {}".format(self.name, self.PID)) logger.info("Server {} running with PID {}".format(self.name, self.PID))
console.info("Server {} running with PID {}".format(self.name, self.PID)) console.info("Server {} running with PID {}".format(self.name, self.PID))
self.is_crashed = False self.is_crashed = False

View File

@ -1,5 +1,5 @@
{ {
"major": 4, "major": 4,
"minor": 0, "minor": 0,
"sub": "Alpha 2" "sub": "Alpha 2+noshell"
} }