команда запуска без shell канала а через exec

v++
This commit is contained in:
2024-12-01 01:07:23 +03:00
parent b76aa24ae4
commit 216b595450
4 changed files with 101 additions and 12 deletions

8
.idea/workspace.xml generated
View File

@@ -7,16 +7,10 @@
</component>
<component name="ChangeListManager">
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/Common/Utils/TimerTask.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/properties" beforeDir="false" afterPath="$PROJECT_DIR$/properties" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/GlobalData/Tasks/Supervisor/Local/Linux/LinuxLocalTaskSupervisor.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/GlobalData/Tasks/Supervisor/Local/Linux/LinuxLocalTaskSupervisor.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/GlobalData/Tasks/Supervisor/Remote/RemoteCompilationSupervisor.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/GlobalData/Tasks/Supervisor/Remote/RemoteCompilationSupervisor.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/GlobalData/Tasks/Supervisor/Remote/RemoteTaskSupervisor.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/GlobalData/Tasks/Supervisor/Remote/RemoteTaskSupervisor.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/GlobalData/Tasks/Supervisor/Remote/ServerRunSupervisor.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/GlobalData/Tasks/Supervisor/Remote/ServerRunSupervisor.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/GlobalData/Tasks/Supervisor/TaskSupervisor.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/GlobalData/Tasks/Supervisor/TaskSupervisor.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/Repository/Component/Visualiser.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/Repository/Component/Visualiser.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/DVM/UserConnection.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/DVM/UserConnection.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/SAPFOR/SapforTestingPlanner.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/_VisualDVM/TestingSystem/SAPFOR/SapforTestingPlanner.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />

View File

@@ -0,0 +1,85 @@
package Common.Utils;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
public abstract class TimerTask {
int maxtime;
int attempts;
boolean success;
Semaphore semaphore = null;
Thread actionThread = null;
//--
public TimerTask(int maxtime_in, int attempts_in) {
maxtime = maxtime_in;
attempts = attempts_in;
semaphore = new Semaphore(1);
actionThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Action();
} catch (Exception ex) {
System.out.println("Thread occured exception!");
ex.printStackTrace();
System.out.println("-------------------------");
} finally {
releaseSemaphore();
}
}
});
}
//--
public abstract void Action() throws Exception;
public void finalizeThread() {
}
void acquireSemaphore() {
try {
semaphore.acquire();
System.out.println("semaphore acquired");
} catch (Exception ignore) {
}
}
void releaseSemaphore() {
semaphore.release();
System.out.println("semaphore released");
}
void waitForThread() {
int i = 0;
success = false;
while (true) {
try {
++i;
if (semaphore.tryAcquire(1, TimeUnit.SECONDS)) {
System.out.println("thread finished for " + i + " seconds");
success = true;
return;
} else {
System.out.println("thread active " + i + " seconds");
if (i >= maxtime) {
System.out.println("maxtime reached: " + i + " seconds");
return;
}
}
} catch (Exception ex) {
System.out.println("waiting exception");
ex.printStackTrace();
return;
}
}
}
public boolean Perform(int attempts) {
int i = 0;
while (i < attempts) {
acquireSemaphore();
actionThread.start();
waitForThread();
finalizeThread();
++i;
System.out.println("task finished for " + i + " attempts");
if (success) {
return true;
}
}
System.out.println("attempts overlimited");
return false;
}
}

View File

@@ -61,7 +61,7 @@ public class Visualiser extends Component {
//http://www.seostella.com/ru/article/2012/02/05/formatirovanie-daty-v-java.html
@Override
public void GetVersionInfo() {
version = 1126;
version = 1127;
String pattern = "MMM dd yyyy HH:mm:ss";
DateFormat df = new SimpleDateFormat(pattern, Locale.ENGLISH);
date_text = df.format(getClassBuildTime());

View File

@@ -413,6 +413,7 @@ public class UserConnection {
}
}
//-----
/*
public void ShellConnect() throws Exception {
shellChannel = (ChannelShell) session.openChannel("shell");
in = new PipedInputStream();
@@ -425,10 +426,6 @@ public class UserConnection {
shellChannel.connect();
//-
fromServer = new InputStreamReader(pout);
/*
ShellParser.setUserName(user.login);
ShellParser.ReadInvitation(fromServer); //прочитать первое приглашение от машины.
*/
}
public void ShellDisconnect() throws Exception {
if (in != null) {
@@ -476,6 +473,8 @@ public class UserConnection {
shellChannel = null;
System.gc();
}
*/
public void waitForFileCreation(RemoteFile file) throws Exception {
while (!Exists(file)) {
System.out.println(file.full_name + " NOT FOUND");
@@ -507,6 +506,16 @@ public class UserConnection {
RemoteFile outFile = new RemoteFile(directory, outFileName);
if (Exists(outFile))
sftpChannel.rm(outFile.full_name);
//--
System.out.println("nohup " + start_command + " &\r\n");
execChannel = (ChannelExec) session.openChannel("exec");
execChannel.setErrStream(System.err);
execChannel.setCommand("nohup " + start_command + " &\r\n");
execChannel.connect();
execChannel.disconnect();
System.out.println("done");
//--
/*
System.out.println("connecting shell");
ShellConnect();
System.out.println("done");
@@ -521,6 +530,7 @@ public class UserConnection {
ShellDisconnect();
System.out.println("done");
// return readFromFile(outFile).replace("\n", "").replace("\r", "");
*/
}
//-- проверка существования рабочего пространства.
public void CheckUserInitialization(String email) throws Exception {