diff --git a/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasProperties.java b/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasProperties.java index e1f3c1abc..fa736cfed 100644 --- a/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasProperties.java +++ b/arthas-spring-boot-starter/src/main/java/com/alibaba/arthas/spring/ArthasProperties.java @@ -34,6 +34,10 @@ public class ArthasProperties { * when arthas agent init error will throw exception by default. */ private boolean slientInit = false; + /** + * disabled commands,default disable stop command + */ + private String disabledCommands = "stop"; public String getHome() { return home; @@ -115,4 +119,11 @@ public class ArthasProperties { this.appName = appName; } + public String getDisabledCommands() { + return disabledCommands; + } + + public void setDisabledCommands(String disabledCommands) { + this.disabledCommands = disabledCommands; + } } diff --git a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java index 368a636b2..109ab832a 100644 --- a/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java +++ b/boot/src/main/java/com/taobao/arthas/boot/Bootstrap.java @@ -1,5 +1,8 @@ package com.taobao.arthas.boot; +import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_ERROR; +import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_TIMEOUT; + import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -11,12 +14,12 @@ import java.security.CodeSource; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.InputMismatchException; import java.util.List; import java.util.Scanner; import java.util.TimeZone; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -import java.util.InputMismatchException; import javax.xml.parsers.ParserConfigurationException; @@ -36,9 +39,6 @@ import com.taobao.middleware.cli.annotations.Name; import com.taobao.middleware.cli.annotations.Option; import com.taobao.middleware.cli.annotations.Summary; -import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_ERROR; -import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_TIMEOUT; - /** * @author hengyunabc 2018-10-26 * @@ -57,6 +57,7 @@ import static com.taobao.arthas.boot.ProcessUtils.STATUS_EXEC_TIMEOUT; + " java -jar arthas-boot.jar --versions\n" + " java -jar arthas-boot.jar --select math-game\n" + " java -jar arthas-boot.jar --session-timeout 3600\n" + " java -jar arthas-boot.jar --attach-only\n" + + " java -jar arthas-boot.jar --disabled-commands stop,dump\n" + " java -jar arthas-boot.jar --repo-mirror aliyun --use-http\n" + "WIKI:\n" + " https://arthas.aliyun.com/doc\n") public class Bootstrap { @@ -128,6 +129,8 @@ public class Bootstrap { private String select; + private String disabledCommands; + static { ARTHAS_LIB_DIR = new File( System.getProperty("user.home") + File.separator + ".arthas" + File.separator + "lib"); @@ -293,6 +296,12 @@ public class Bootstrap { this.select = select; } + @Option(longName = "disabled-commands") + @Description("disable some commands ") + public void setDisabledCommands(String disabledCommands) { + this.disabledCommands = disabledCommands; + } + public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException, ClassNotFoundException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { @@ -547,6 +556,11 @@ public class Bootstrap { attachArgs.add(bootstrap.getStatUrl()); } + if (bootstrap.getDisabledCommands() != null){ + attachArgs.add("-disabled-commands"); + attachArgs.add(bootstrap.getDisabledCommands()); + } + AnsiLog.info("Try to attach process " + pid); AnsiLog.debug("Start arthas-core.jar args: " + attachArgs); ProcessUtils.startArthasCore(pid, attachArgs); @@ -849,4 +863,8 @@ public class Bootstrap { public String getPassword() { return password; } + + public String getDisabledCommands() { + return disabledCommands; + } } diff --git a/core/src/main/java/arthas.properties b/core/src/main/java/arthas.properties index d8bca548e..e562eea80 100644 --- a/core/src/main/java/arthas.properties +++ b/core/src/main/java/arthas.properties @@ -16,4 +16,6 @@ arthas.sessionTimeout=1800 #arthas.tunnelServer=ws://127.0.0.1:7777/ws #arthas.agentId=mmmmmmyiddddd +#arthas.disabledCommands=stop,dump + #arthas.outputPath=arthas-output \ No newline at end of file diff --git a/core/src/main/java/com/taobao/arthas/core/Arthas.java b/core/src/main/java/com/taobao/arthas/core/Arthas.java index 60c7b4839..c3375e6f8 100644 --- a/core/src/main/java/com/taobao/arthas/core/Arthas.java +++ b/core/src/main/java/com/taobao/arthas/core/Arthas.java @@ -46,11 +46,12 @@ public class Arthas { Option appName = new TypedOption().setType(String.class).setShortName(ArthasConstants.APP_NAME); Option statUrl = new TypedOption().setType(String.class).setShortName("stat-url"); + Option disabledCommands = new TypedOption().setType(String.class).setShortName("disabled-commands"); CLI cli = CLIs.create("arthas").addOption(pid).addOption(core).addOption(agent).addOption(target) .addOption(telnetPort).addOption(httpPort).addOption(sessionTimeout) .addOption(username).addOption(password) - .addOption(tunnelServer).addOption(agentId).addOption(appName).addOption(statUrl); + .addOption(tunnelServer).addOption(agentId).addOption(appName).addOption(statUrl).addOption(disabledCommands); CommandLine commandLine = cli.parse(Arrays.asList(args)); Configure configure = new Configure(); @@ -78,6 +79,7 @@ public class Arthas { configure.setTunnelServer((String) commandLine.getOptionValue("tunnel-server")); configure.setAgentId((String) commandLine.getOptionValue("agent-id")); configure.setStatUrl((String) commandLine.getOptionValue("stat-url")); + configure.setDisabledCommands((String) commandLine.getOptionValue("disabled-commands")); configure.setAppName((String) commandLine.getOptionValue(ArthasConstants.APP_NAME)); return configure; } diff --git a/core/src/main/java/com/taobao/arthas/core/config/Configure.java b/core/src/main/java/com/taobao/arthas/core/config/Configure.java index a3b7ba34e..433b22131 100644 --- a/core/src/main/java/com/taobao/arthas/core/config/Configure.java +++ b/core/src/main/java/com/taobao/arthas/core/config/Configure.java @@ -60,6 +60,11 @@ public class Configure { */ private Long sessionTimeout; + /** + * disabled commands + */ + private String disabledCommands; + public String getIp() { return ip; } @@ -180,6 +185,14 @@ public class Configure { this.password = password; } + public String getDisabledCommands() { + return disabledCommands; + } + + public void setDisabledCommands(String disabledCommands) { + this.disabledCommands = disabledCommands; + } + /** * 序列化成字符串 *