1 Reply Latest reply on Feb 27, 2015 5:27 PM by Rich DiCroce

    Best way to shutdown Wildfly from within my deployment

    initialzero Newbie

      I have a rar that I want to shutdown wildfly if a certain situation arises. I was thinking of using the CLI module to execute a shutdown. What would be the best practice in this situation. My only issue so far with using the CLI module is a ClassNotFound exception even though the dependency seems to be configured correctly.

      Any help would be appreciated.

        • 1. Re: Best way to shutdown Wildfly from within my deployment
          Rich DiCroce Novice

          I've done it using JMX. No extra dependencies required. Code snippets:

           

          SHUTDOWN_SIGNATURE = new String[] {boolean.class.getName()};

          mbeanServer = ManagementFactory.getPlatformMBeanServer();

          jmxServerObjectName = new ObjectName("jboss.as:management-root=server");

          mbeanServer.invoke(jmxServerObjectName, "shutdown",

                              new Object[] {false}, SHUTDOWN_SIGNATURE);

           

          All classes used above are part of the JDK. The boolean parameter in the Object array indicates whether you want to restart WildFly after shutting it down. If you need to do anything else, the whole management API is exposed through JMX, so anything listed at http://wildscribe.github.io/ is available.