Исправление зависания кнопки запуска сервера
This commit is contained in:
2024-04-09 19:46:15 +03:00
parent 3d70efe253
commit e4fe527365
11 changed files with 29 additions and 43 deletions

View File

@@ -2,7 +2,6 @@ package TestingSystem.DVM;
import Common.Constants;
import Common.Global;
import Common.Utils.Utils;
import Common.Utils.Validators.ShellParser;
import GlobalData.Machine.Machine;
import GlobalData.RemoteFile.RemoteFile;
import GlobalData.User.User;
@@ -16,6 +15,7 @@ import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.Vector;
public class UserConnection {
//http://www.jcraft.com/jsch/
public int iterations = 0; //для тестирования
//--
public ChannelSftp sftpChannel = null;
@@ -402,14 +402,6 @@ public class UserConnection {
execChannel.disconnect();
}
}
public void performScriptNoWait(RemoteFile directory, String... commands) throws Exception {
RemoteFile script_file = new RemoteFile(directory, Constants.script);
if (Exists(script_file))
sftpChannel.rm(script_file.full_name);
//--
writeToFile("cd " + Utils.DQuotes(directory.full_name) + "\n" + String.join("\n", commands), script_file);
CommandNoWait(Utils.DQuotes(script_file.full_name));
}
//-----
public void ShellConnect() throws Exception {
shellChannel = (ChannelShell) session.openChannel("shell");
@@ -474,20 +466,13 @@ public class UserConnection {
shellChannel = null;
System.gc();
}
public void ShellCommandNoWait(String command) throws Exception {
ShellConnect();
pin.write(("nohup " + command + " &\r\n").getBytes());
ShellParser.ReadCommand(command, fromServer); //команда
System.out.println("+++++++++++++++++");
ShellParser.ReadCommand(command, fromServer); //эхо
ShellDisconnect();
}
public String startProcess(RemoteFile directory, String... commands) throws Exception {
//возможно в дальнейшем обобщить чтобы вместо PID был файл вывода с задаваемым именем?
public String startShellProcess(RemoteFile directory, String outFileName, String... commands) throws Exception {
Vector<String> commands_ = new Vector<>();
commands_.add("cd " + Utils.DQuotes(directory.full_name));
for (int i = 0; i < commands.length; ++i) {
if (i == commands.length - 1) {
commands_.add(commands[i] + " 1>PID");
commands_.add(commands[i] + " 1>"+Utils.DQuotes(outFileName));
} else {
commands_.add(commands[i]);
}
@@ -498,14 +483,14 @@ public class UserConnection {
writeToFile(String.join("\n", commands_), script_file);
String start_command = Utils.DQuotes(script_file.full_name);
//--
RemoteFile PID = new RemoteFile(directory, "PID");
RemoteFile outFile = new RemoteFile(directory, outFileName);
ShellConnect();
pin.write(("nohup " + start_command + " &\r\n").getBytes());
while (!Exists(PID)){
System.out.println("PID NOT FOUND");
while (!Exists(outFile)){
System.out.println(outFileName +" NOT FOUND");
Utils.sleep(1000);
}
ShellDisconnect();
return readFromFile(PID).replace("\n","").replace("\r","");
return readFromFile(outFile).replace("\n","").replace("\r","");
}
}