mirror of
https://gitee.com/arthas/arthas.git
synced 2024-12-02 04:08:34 +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
|
||||
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] If you still want to attach target process $TARGET_PID, Try to set a different telnet port by using --telnet-port argument."
|
||||
echo "[ERROR] Or try to shutdown the process $telnetPortPid using the telnet port first."
|
||||
echo "[ERROR] 1. Try to restart as.sh, select process $telnetPortPid, shutdown it first."
|
||||
echo "[ERROR] 2. Try to use different telnet port, for example: as.sh --telnet-port 9998 --http-port -1"
|
||||
exit 1
|
||||
fi
|
||||
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 "If you still want to attach target process $TARGET_PID, Try to set a different telnet port by using --telnet-port argument."
|
||||
echo "Or try to shutdown the process $httpPortPid using the telnet port first."
|
||||
echo "1. Try to restart as.sh, select process $httpPortPid, shutdown it first."
|
||||
echo "2. Try to use different http port, for example: as.sh --telnet-port 9998 --http-port 9999"
|
||||
exit 1
|
||||
fi
|
||||
elif [ -z ${TARGET_PID} ]; then
|
||||
|
@ -271,7 +271,7 @@ public class Bootstrap {
|
||||
// select pid
|
||||
if (pid < 0) {
|
||||
try {
|
||||
pid = ProcessUtils.select(bootstrap.isVerbose());
|
||||
pid = ProcessUtils.select(bootstrap.isVerbose(), telnetPortPid);
|
||||
} catch (InputMismatchException e) {
|
||||
System.out.println("Please input an integer to select pid.");
|
||||
System.exit(1);
|
||||
@ -285,18 +285,18 @@ public class Bootstrap {
|
||||
if (telnetPortPid > 0 && pid != telnetPortPid) {
|
||||
AnsiLog.error("Target process {} is not the process using port {}, you will connect to an unexpected process.",
|
||||
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.",
|
||||
pid);
|
||||
AnsiLog.error("Or try to shutdown the process {} using the telnet port first.", telnetPortPid);
|
||||
AnsiLog.error("1. Try to restart arthas-boot, select process {}, shutdown it 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);
|
||||
}
|
||||
|
||||
if (httpPortPid > 0 && pid != httpPortPid) {
|
||||
AnsiLog.error("Target process {} is not the process using port {}, you will connect to an unexpected process.",
|
||||
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.",
|
||||
pid);
|
||||
AnsiLog.error("Or try to shutdown the process {} using the http port first.", httpPortPid);
|
||||
AnsiLog.error("1. Try to restart arthas-boot, select process {}, shutdown it 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);
|
||||
}
|
||||
|
||||
|
@ -47,8 +47,17 @@ public class ProcessUtils {
|
||||
}
|
||||
|
||||
@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);
|
||||
// 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()) {
|
||||
AnsiLog.info("Can not find java process. Try to pass <pid> in command line.");
|
||||
|
Loading…
Reference in New Issue
Block a user