diff --git a/.run/Agent-dev-1.run.xml b/.run/Agent-dev-1.run.xml
new file mode 100644
index 0000000..f6486b5
--- /dev/null
+++ b/.run/Agent-dev-1.run.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java b/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java
index b5da215..e73f5ce 100644
--- a/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java
+++ b/agent/src/main/java/io/wdd/agent/executor/CommandExecutor.java
@@ -11,7 +11,6 @@ import org.apache.commons.lang3.ObjectUtils;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
-import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
@@ -76,15 +75,23 @@ public class CommandExecutor {
private int processExecute(String streamKey, ProcessBuilder processBuilder) {
-
+ // 重定向,错误日志到标准输出中
processBuilder.redirectErrorStream(true);
-// processBuilder.inheritIO();
- processBuilder.directory(new File(System.getProperty("user.home")));
+ //processBuilder.inheritIO();
+ //processBuilder.directory(new File(System.getProperty("user.home")));
int processResult = 233;
try {
+ // 开始执行命令之前,需要进行打印
+ log.debug(
+ "current shell command {}",
+ processBuilder.command()
+ );
+
+ // 开始执行命令操作
Process process = processBuilder.start();
+
// start a backend thread to daemon the process
// wait for processMaxWaitSeconds and kill the process if it's still alived
DaemonCommandProcess.submit(
@@ -93,14 +100,15 @@ public class CommandExecutor {
processMaxWaitSeconds
));
- // cache log lines
+
+ // 缓存让命令处理日志,并且打印
logToArrayListCache.cacheLog(
streamKey,
process
);
// start to send the result log
- streamSender.startToWaitLog(streamKey);
+ //streamSender.startToWaitLog(streamKey);
// todo this will stuck the process and rabbitmq message will reentry the queue
// get the command result must also be a timeout smaller than the process
@@ -109,8 +117,10 @@ public class CommandExecutor {
TimeUnit.SECONDS
);
+
+
// end send logs
- streamSender.endWaitLog(streamKey);
+ //streamSender.endWaitLog(streamKey);
// get the process result
if (ObjectUtils.isNotEmpty(waitFor) && ObjectUtils.isNotEmpty(process)) {
diff --git a/agent/src/main/java/io/wdd/agent/executor/thread/LogToArrayListCache.java b/agent/src/main/java/io/wdd/agent/executor/thread/LogToArrayListCache.java
index e5765b2..817e05f 100644
--- a/agent/src/main/java/io/wdd/agent/executor/thread/LogToArrayListCache.java
+++ b/agent/src/main/java/io/wdd/agent/executor/thread/LogToArrayListCache.java
@@ -14,7 +14,6 @@ import java.util.List;
/**
* utils to cache store the command execution logs
- *
*/
@Component
@Slf4j
@@ -35,7 +34,13 @@ public class LogToArrayListCache {
ArrayList commandCachedLog = this.getExecutionCmdCachedLogArrayList(streamKey);
- String format = String.format("execution command are => [ %s ]", process.info().commandLine().get());
+ String format = String.format(
+ "execution command are => [ %s ]",
+ process
+ .info()
+ .commandLine()
+ .get()
+ );
// add the command
commandCachedLog.add("");
@@ -44,16 +49,17 @@ public class LogToArrayListCache {
commandCachedLog.add("");
// cache the real command logs
- cacheLog(streamKey, process.getInputStream());
+ doCacheLog(
+ streamKey,
+ process.getInputStream()
+ );
}
- public void cacheLog(String streamKey, InputStream commandLogStream) {
+ private void doCacheLog(String streamKey, InputStream commandLogStream) {
ArrayList commandCachedLog = this.getExecutionCmdCachedLogArrayList(streamKey);
-// log.info(String.valueOf(commandCachedLog));
-
// read from input stream and store to the cacheArrayList
new BufferedReader(new InputStreamReader(commandLogStream))
.lines()
@@ -61,7 +67,11 @@ public class LogToArrayListCache {
commandCachedLog::add
);
- log.debug("current streamKey is {} and CacheLog is {}", streamKey, commandCachedLog);
+ log.debug(
+ "current streamKey is {} and CacheLog is {}",
+ streamKey,
+ commandCachedLog
+ );
}
public ArrayList getExecutionCmdCachedLogArrayList(String streamKey) {
@@ -85,9 +95,9 @@ public class LogToArrayListCache {
boolean hasRehashed = false;
if (CollectionUtils.isNotEmpty(CachedCommandLog.get(result))) {
- for (int index = result+1; index < CachedCommandLog.size(); index++) {
+ for (int index = result + 1; index < CachedCommandLog.size(); index++) {
// from the index to the end
- if (CollectionUtils.isEmpty(CachedCommandLog.get(index))){
+ if (CollectionUtils.isEmpty(CachedCommandLog.get(index))) {
hasRehashed = true;
result = index;
break;
@@ -96,7 +106,7 @@ public class LogToArrayListCache {
if (!hasRehashed) {
for (int index = 0; index < result; index++) {
// from begin to the index
- if (CollectionUtils.isEmpty(CachedCommandLog.get(index))){
+ if (CollectionUtils.isEmpty(CachedCommandLog.get(index))) {
hasRehashed = true;
result = index;
break;
diff --git a/server/src/main/java/io/wdd/func/xray/beans/node/ProxyNodeSet.java b/server/src/main/java/io/wdd/func/xray/beans/node/ProxyNodeSet.java
index edd58a7..e5fffdb 100644
--- a/server/src/main/java/io/wdd/func/xray/beans/node/ProxyNodeSet.java
+++ b/server/src/main/java/io/wdd/func/xray/beans/node/ProxyNodeSet.java
@@ -14,7 +14,9 @@ public class ProxyNodeSet {
public static ProxyNode phoenix2;
public static ProxyNode london2;
+ // 开发使用
public static ProxyNode chengduAgent;
+ public static ProxyNode tokyoDev;
static {
@@ -92,7 +94,7 @@ public class ProxyNodeSet {
.agentName("London-amd64-02")
.build();
- chengduAgent = ProxyNode
+ tokyoDev = ProxyNode
.builder()
.location("Tokyo")
.num(99)
@@ -103,6 +105,18 @@ public class ProxyNodeSet {
.agentTopicName("Tokyo-amd64-07-f66a41")
.build();
+
+ chengduAgent = ProxyNode
+ .builder()
+ .location("Chengdu")
+ .num(90)
+ .publicIPv4("183.220.9.13")
+ .proxyNodeType(ProxyNodeType.EXTERNAL)
+ .name("chengdu-agent")
+ .agentName("Chengdu-amd64-77")
+ .agentTopicName("Chengdu-amd64-77-remote")
+ .build();
+
ProxyNodeMap.put(chengdu.getNum(), chengdu);
ProxyNodeMap.put(hongkong.getNum(), hongkong);
ProxyNodeMap.put(shanghai.getNum(), shanghai);
@@ -111,6 +125,7 @@ public class ProxyNodeSet {
ProxyNodeMap.put(phoenix2.getNum(), phoenix2);
ProxyNodeMap.put(london2.getNum(), london2);
ProxyNodeMap.put(chengduAgent.getNum(), chengduAgent);
+ ProxyNodeMap.put(tokyoDev.getNum(), tokyoDev);
}
diff --git a/server/src/main/java/io/wdd/func/xray/service/XrayConfigDistribute.java b/server/src/main/java/io/wdd/func/xray/service/XrayConfigDistribute.java
index 615eee0..c8bf578 100644
--- a/server/src/main/java/io/wdd/func/xray/service/XrayConfigDistribute.java
+++ b/server/src/main/java/io/wdd/func/xray/service/XrayConfigDistribute.java
@@ -41,7 +41,7 @@ public class XrayConfigDistribute {
static {
- ArrayList zero = new ArrayList<>(
+ /*ArrayList zero = new ArrayList<>(
List.of(
"if",
"[",
@@ -56,7 +56,7 @@ public class XrayConfigDistribute {
";",
"fi"
)
- );
+ );*/
ArrayList first = new ArrayList<>(
@@ -92,13 +92,12 @@ public class XrayConfigDistribute {
"|",
"grep",
"-c",
- "active,(running)"
+ "active (running)"
)
);
- updateXrayCommandList.add(zero);
updateXrayCommandList.add(first);
updateXrayCommandList.add(second);
updateXrayCommandList.add(third);
@@ -166,10 +165,10 @@ public class XrayConfigDistribute {
}
// 修改命令中的时间
String s = updateXrayCommandList
- .get(1)
+ .get(0)
.get(2);
updateXrayCommandList
- .get(1)
+ .get(0)
.set(
2,
s.replace(
@@ -180,7 +179,7 @@ public class XrayConfigDistribute {
// 修改命令中的下载url
updateXrayCommandList
- .get(2)
+ .get(1)
.set(
1,
realUrl