Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added port tests to avoid long stacktrace when there's already a serv…

…er running
  • Loading branch information...
commit f2f37f1223f747eb8161e81dc58fa6a31137f73c 1 parent 82e8434
Burt Beckwith burtbeckwith authored

Showing 1 changed file with 26 additions and 12 deletions. Show diff stats Hide diff stats

  1. +26 12 scripts/_GrailsRun.groovy
38 scripts/_GrailsRun.groovy
@@ -14,12 +14,14 @@
14 14 * limitations under the License.
15 15 */
16 16
17   -import org.codehaus.groovy.grails.cli.interactive.InteractiveMode
18   -import org.codehaus.groovy.grails.cli.GrailsScriptRunner
19 17 import grails.util.GrailsUtil
20   -
21   -import grails.web.container.EmbeddableServerFactory
  18 +import grails.util.Metadata
22 19 import grails.web.container.EmbeddableServer
  20 +import grails.web.container.EmbeddableServerFactory
  21 +
  22 +import java.net.ServerSocket
  23 +
  24 +import org.codehaus.groovy.grails.cli.interactive.InteractiveMode
23 25
24 26 /**
25 27 * Gant script that executes Grails using an embedded server
@@ -85,7 +87,6 @@ target (runWarHttps : "Main implementation that executes a Grails application WA
85 87 private EmbeddableServerFactory loadServerFactory() {
86 88 def load = { name -> classLoader.loadClass(name).newInstance() }
87 89
88   -
89 90 String defaultServer = "org.grails.plugins.tomcat.TomcatServerFactory"
90 91 def containerClass = getPropertyValue("grails.server.factory", defaultServer)
91 92 EmbeddableServerFactory serverFactory
@@ -121,9 +122,8 @@ private runWar(scheme, host, httpPort, httpsPort) {
121 122 EmbeddableServerFactory serverFactory = loadServerFactory()
122 123 grailsServer = serverFactory.createForWAR(warName, serverContextPath)
123 124
124   - grails.util.Metadata.getCurrent().put(grails.util.Metadata.WAR_DEPLOYED, "true")
  125 + Metadata.getCurrent().put(Metadata.WAR_DEPLOYED, "true")
125 126 runServer server:grailsServer, host:host, httpPort:httpPort, httpsPort: httpsPort, scheme: scheme
126   -
127 127 }
128 128
129 129 /**
@@ -147,7 +147,21 @@ runServer = { Map args ->
147 147 }
148 148
149 149 profile("start server") {
  150 +
  151 + try { new ServerSocket(args.httpPort).close() }
  152 + catch (IOException e) {
  153 + event("StatusFinal", ["Server failed to start for port $args.httpPort: $e.message"])
  154 + exit(1)
  155 + }
  156 +
150 157 if (args.scheme == 'https') {
  158 +
  159 + try { new ServerSocket(args.httpsPort).close() }
  160 + catch (IOException e) {
  161 + event("StatusFinal", ["Server failed to start for port $args.httpsPort: $e.message"])
  162 + exit(1)
  163 + }
  164 +
151 165 usingSecureServer = true
152 166 server.startSecure args.host, args.httpPort, args.httpsPort
153 167
@@ -192,11 +206,11 @@ target(watchContext: "Watches the WEB-INF/classes directory for changes and rest
192 206 depends(classpath)
193 207
194 208 if (InteractiveMode.current) {
195   - Thread.start {
196   - def im = InteractiveMode.current
197   - im.grailsServer = grailsServer
198   - im.run()
199   - }
  209 + Thread.start {
  210 + def im = InteractiveMode.current
  211 + im.grailsServer = grailsServer
  212 + im.run()
  213 + }
200 214 }
201 215
202 216 keepServerAlive()

0 comments on commit f2f37f1

Please sign in to comment.
Something went wrong with that request. Please try again.