mirror of
https://gitee.com/arthas/arthas.git
synced 2024-11-30 03:07:37 +08:00
better way to select process and better error info. close #445
This commit is contained in:
parent
f6d2c9eb7c
commit
1cec77997f
@ -635,14 +635,14 @@ parse_arguments()
|
|||||||
# check the process already using telnet port if equals to target pid
|
# check the process already using telnet port if equals to target pid
|
||||||
if [[ ($telnetPortPid) && ($TARGET_PID != $telnetPortPid) ]]; then
|
if [[ ($telnetPortPid) && ($TARGET_PID != $telnetPortPid) ]]; then
|
||||||
echo "[ERROR] Target process $TARGET_PID is not the process using port $TELNET_PORT, you will connect to an unexpected process."
|
echo "[ERROR] Target process $TARGET_PID is not the process using port $TELNET_PORT, you will connect to an unexpected process."
|
||||||
echo "[ERROR] If you still want to attach target process $TARGET_PID, Try to set a different telnet port by using --telnet-port argument."
|
echo "[ERROR] 1. Try to restart as.sh, select process $telnetPortPid, shutdown it first."
|
||||||
echo "[ERROR] Or try to shutdown the process $telnetPortPid using the telnet port first."
|
echo "[ERROR] 2. Try to use different telnet port, for example: as.sh --telnet-port 9998 --http-port -1"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [[ ($httpPortPid) && ($TARGET_PID != $httpPortPid) ]]; then
|
if [[ ($httpPortPid) && ($TARGET_PID != $httpPortPid) ]]; then
|
||||||
echo "Target process $TARGET_PID is not the process using port $HTTP_PORT, you will connect to an unexpected process."
|
echo "Target process $TARGET_PID is not the process using port $HTTP_PORT, you will connect to an unexpected process."
|
||||||
echo "If you still want to attach target process $TARGET_PID, Try to set a different telnet port by using --telnet-port argument."
|
echo "1. Try to restart as.sh, select process $httpPortPid, shutdown it first."
|
||||||
echo "Or try to shutdown the process $httpPortPid using the telnet port first."
|
echo "2. Try to use different http port, for example: as.sh --telnet-port 9998 --http-port 9999"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
elif [ -z ${TARGET_PID} ]; then
|
elif [ -z ${TARGET_PID} ]; then
|
||||||
|
@ -271,7 +271,7 @@ public class Bootstrap {
|
|||||||
// select pid
|
// select pid
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
try {
|
try {
|
||||||
pid = ProcessUtils.select(bootstrap.isVerbose());
|
pid = ProcessUtils.select(bootstrap.isVerbose(), telnetPortPid);
|
||||||
} catch (InputMismatchException e) {
|
} catch (InputMismatchException e) {
|
||||||
System.out.println("Please input an integer to select pid.");
|
System.out.println("Please input an integer to select pid.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
@ -285,18 +285,18 @@ public class Bootstrap {
|
|||||||
if (telnetPortPid > 0 && pid != telnetPortPid) {
|
if (telnetPortPid > 0 && pid != telnetPortPid) {
|
||||||
AnsiLog.error("Target process {} is not the process using port {}, you will connect to an unexpected process.",
|
AnsiLog.error("Target process {} is not the process using port {}, you will connect to an unexpected process.",
|
||||||
pid, bootstrap.getTelnetPort());
|
pid, bootstrap.getTelnetPort());
|
||||||
AnsiLog.error("If you still want to attach target process {}, Try to set a different telnet port by using --telnet-port argument.",
|
AnsiLog.error("1. Try to restart arthas-boot, select process {}, shutdown it first.",
|
||||||
pid);
|
telnetPortPid);
|
||||||
AnsiLog.error("Or try to shutdown the process {} using the telnet port first.", telnetPortPid);
|
AnsiLog.error("2. Or try to use different telnet port, for example: java -jar arthas-boot.jar --telnet-port 9998 --http-port -1");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (httpPortPid > 0 && pid != httpPortPid) {
|
if (httpPortPid > 0 && pid != httpPortPid) {
|
||||||
AnsiLog.error("Target process {} is not the process using port {}, you will connect to an unexpected process.",
|
AnsiLog.error("Target process {} is not the process using port {}, you will connect to an unexpected process.",
|
||||||
pid, bootstrap.getHttpPort());
|
pid, bootstrap.getHttpPort());
|
||||||
AnsiLog.error("If you still want to attach target process {}, Try to set a different http port by using --http-port argument.",
|
AnsiLog.error("1. Try to restart arthas-boot, select process {}, shutdown it first.",
|
||||||
pid);
|
httpPortPid);
|
||||||
AnsiLog.error("Or try to shutdown the process {} using the http port first.", httpPortPid);
|
AnsiLog.error("2. Or try to use different http port, for example: java -jar arthas-boot.jar --telnet-port 9998 --http-port 9999", httpPortPid);
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,8 +47,17 @@ public class ProcessUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
public static int select(boolean v) throws InputMismatchException {
|
public static int select(boolean v, int telnetPortPid) throws InputMismatchException {
|
||||||
Map<Integer, String> processMap = listProcessByJps(v);
|
Map<Integer, String> processMap = listProcessByJps(v);
|
||||||
|
// Put the port that is already listening at the first
|
||||||
|
if (telnetPortPid > 0 && processMap.containsKey(telnetPortPid)) {
|
||||||
|
String telnetPortProcess = processMap.get(telnetPortPid);
|
||||||
|
processMap.remove(telnetPortPid);
|
||||||
|
Map<Integer, String> newProcessMap = new LinkedHashMap<Integer, String>();
|
||||||
|
newProcessMap.put(telnetPortPid, telnetPortProcess);
|
||||||
|
newProcessMap.putAll(processMap);
|
||||||
|
processMap = newProcessMap;
|
||||||
|
}
|
||||||
|
|
||||||
if (processMap.isEmpty()) {
|
if (processMap.isEmpty()) {
|
||||||
AnsiLog.info("Can not find java process. Try to pass <pid> in command line.");
|
AnsiLog.info("Can not find java process. Try to pass <pid> in command line.");
|
||||||
|
Loading…
Reference in New Issue
Block a user