Skip to content

Commit

Permalink
Give help infomation to enable '/shutdown' endpoint when executing `s…
Browse files Browse the repository at this point in the history
…top-app` failed

Closes gh-18
  • Loading branch information
rainboyan committed Nov 29, 2024
1 parent 5f75b11 commit 26fecaa
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions commands/stop-app.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import javax.management.remote.JMXServiceURL
import javax.management.remote.JMXConnectorFactory
import javax.management.ObjectName
import org.grails.io.support.*

description("Stops the running Grace application") {
Expand All @@ -9,31 +6,43 @@ description("Stops the running Grace application") {
flag name:'port', description:"Specifies the port which the Grace application is running on (defaults to 8080 or 8443 for HTTPS)"
flag name:'host', description:"Specifies the host the Grace application is bound to"
}

System.setProperty("run-app.running", "false")

Integer port = flag('port')?.toInteger() ?: config.getProperty('server.port', Integer) ?: 8080
String host = flag('host') ?: config.getProperty('server.address', String) ?: "localhost"
String contextPath = config.getProperty('server.context-path') ?: config.getProperty('server.contextPath') ?: ""
String managementPath = config.getProperty('management.endpoints.web.base-path') ?: config.getProperty('management.endpoints.web.basePath') ?: "/actuator"
console.updateStatus "Shutting down application..."

def url = new URL("http://$host:${port}${contextPath}${managementPath}/shutdown")
try {
def connection = url.openConnection()
connection.setRequestMethod("POST")
connection.doOutput = true
connection.connect()
console.updateStatus connection.content.text
while(isServerAvailable(host, port)) {
sleep 100
}
console.updateStatus "Application shutdown."
return true

def connection = url.openConnection()
connection.setRequestMethod("POST")
connection.doOutput = true
connection.connect()
console.updateStatus connection.content.text
while(isServerAvailable(host, port)) {
sleep 100
}
console.updateStatus "Application shutdown."
return true
}
catch (e) {
console.error "Application not running.", e
return false
catch (java.net.ConnectException e) {
console.error "Application not running.", e
return true
}


catch (java.io.FileNotFoundException ignored) {
console.info '''# Please check that '/shutdown' endpoint enabled in 'app/conf/application.yml'
management:
endpoint:
shutdown:
enabled: true
'''
return true
}
catch (Exception e) {
console.error "Application shutdown error: ", e
return true
}

0 comments on commit 26fecaa

Please sign in to comment.