support listen random port. #524

This commit is contained in:
hengyunabc
2020-09-02 18:07:56 +08:00
parent 0af6ef061e
commit a1c8f43032
2 changed files with 104 additions and 2 deletions
@@ -27,6 +27,7 @@ import com.alibaba.arthas.deps.org.slf4j.LoggerFactory;
import com.alibaba.arthas.tunnel.client.TunnelClient;
import com.taobao.arthas.common.AnsiLog;
import com.taobao.arthas.common.PidUtils;
import com.taobao.arthas.common.SocketUtils;
import com.taobao.arthas.core.advisor.TransformerManager;
import com.taobao.arthas.core.command.BuiltinCommandPack;
import com.taobao.arthas.core.command.view.ResultViewResolver;
@@ -274,6 +275,18 @@ public class ArthasBootstrap {
throw new IllegalStateException("already bind");
}
// init random port
if (configure.getTelnetPort() == 0) {
int newTelnetPort = SocketUtils.findAvailableTcpPort();
configure.setTelnetPort(newTelnetPort);
logger().info("generate random telnet port: " + newTelnetPort);
}
if (configure.getHttpPort() == 0) {
int newHttpPort = SocketUtils.findAvailableTcpPort();
configure.setHttpPort(newHttpPort);
logger().info("generate random http port: " + newHttpPort);
}
String agentId = null;
try {
if (configure.getTunnelServer() != null && configure.getHttpPort() > 0) {