jdaugherty commented on code in PR #15698:
URL: https://github.com/apache/grails-core/pull/15698#discussion_r3343425420


##########
grails-profiles/base/commands/stop-app.groovy:
##########
@@ -1,101 +1,22 @@
-import javax.management.remote.JMXServiceURL
-import javax.management.remote.JMXConnectorFactory
-import javax.management.ObjectName
-import org.grails.io.support.*
-import groovy.jmx.GroovyMBean
-
 description("Stops the running Grails application") {
     usage "grails stop-app"
     synonyms 'stop'
-    flag name:'port', description:"Specifies the port which the Grails 
application is running on (defaults to 8080 or 8443 for HTTPS)"
-    flag name:'host', description:"Specifies the host the Grails application 
is bound to"
-}
-System.setProperty("run-app.running", "false")
-def getJMXLocalConnectorAddresses = {->
-       final applicationMainClassName = MainClassFinder.findMainClass()
-
-       if(applicationMainClassName) {
-               try {
-                   final String CONNECTOR_ADDRESS = 
"com.sun.management.jmxremote.localConnectorAddress"
-                   def VirtualMachine = 
getClass().classLoader.loadClass('com.sun.tools.attach.VirtualMachine')
-                   return VirtualMachine.list()
-                       .findAll { 
-                               it.displayName() == applicationMainClassName 
-                       }
-                       .collect { desc ->
-                           def vm = VirtualMachine.attach(desc.id())
-                           try {
-                               def connectorAddress = 
vm.agentProperties.getProperty(CONNECTOR_ADDRESS)
-                               if (connectorAddress == null) {
-                                   // Trying to load agent
-                                   def agent = 
[vm.systemProperties.getProperty("java.home"), "lib", 
"management-agent.jar"].join(File.separator)
-                                   vm.loadAgent(agent)
-
-                                   connectorAddress = 
vm.agentProperties.getProperty(CONNECTOR_ADDRESS)
-                               }
-                               if (connectorAddress) {
-                                   return connectorAddress
-                               }
-                           } finally {
-                               vm.detach()
-                           }
-                       }.findAll { it }
-                               
-               }
-               catch(Throwable e) {
-                       // fallback to REST request if JMX not available
-               }
-       }
 }
 
+System.setProperty("run-app.running", "false")
 
-def addresses = getJMXLocalConnectorAddresses() 
-if(addresses) {
-       JMXServiceURL url = new JMXServiceURL(addresses[0])
-       def connector = JMXConnectorFactory.connect(url)
-
-       try {
-           def server = connector.MBeanServerConnection
+console.updateStatus "Stopping application..."
 
-           def objectName = server.queryNames(null,null).find {  
it.canonicalName.contains('name=shutdownEndpoint,type=Endpoint') }
-           def mbean = new GroovyMBean(server, objectName)
-       console.addStatus "Shutting down application..."
-        mbean.shutdown()
-        console.addStatus "Application shutdown."
-        return true
+if (org.grails.cli.gradle.RunningApplicationRegistry.stopAll()) {

Review Comment:
   Doesn't this only worked for non-forked processes? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to