How to use command to shutdown grails run-app
Asked Answered
R

9

17

After executing grails run-app, except using Ctrl + C", is there a command to shutdown it?

Roberts answered 27/8, 2010 at 15:42 Comment(0)
T
12

No. grails run-app is intended to be run for development, interactively.

If you want to control grails as a service, you should deploy it to a web application container such as tomcat. The tomcat plugin allows you to easily deploy your app to tomcat, for example. Add lines like

tomcat.deploy.username="manager"
tomcat.deploy.password="secret"
tomcat.deploy.url="http://myserver.com/manager"

to Config.groovy and then you can use

grails tomcat deploy
grails tomcat undeploy

to start and stop your application. Alternatively, you can use grails war to bundle your app into a war archive which all java app servers should be able to use.

If you really want to stop grails run-app without Ctrl+C, write a small controller that calls System.exit(0). Then browse to that URL, or write a small shell script or batch file that invokes it with e.g. wget or curl.

Treble answered 27/8, 2010 at 19:58 Comment(1)
If you do go the route of a web-accessible controller action to kill the application, make sure to either remove it prior to deploying to production, or secure it heavily so that malicious users can't just kill your app.Plummy
P
14

For Stop Server

Exit from the terminal and use any one from the commands below:

  • grails exit
  • grails stop-app
  • grails quit
Prenatal answered 1/11, 2013 at 10:58 Comment(0)
T
12

No. grails run-app is intended to be run for development, interactively.

If you want to control grails as a service, you should deploy it to a web application container such as tomcat. The tomcat plugin allows you to easily deploy your app to tomcat, for example. Add lines like

tomcat.deploy.username="manager"
tomcat.deploy.password="secret"
tomcat.deploy.url="http://myserver.com/manager"

to Config.groovy and then you can use

grails tomcat deploy
grails tomcat undeploy

to start and stop your application. Alternatively, you can use grails war to bundle your app into a war archive which all java app servers should be able to use.

If you really want to stop grails run-app without Ctrl+C, write a small controller that calls System.exit(0). Then browse to that URL, or write a small shell script or batch file that invokes it with e.g. wget or curl.

Treble answered 27/8, 2010 at 19:58 Comment(1)
If you do go the route of a web-accessible controller action to kill the application, make sure to either remove it prior to deploying to production, or secure it heavily so that malicious users can't just kill your app.Plummy
K
9

Open a new command line window, go to the project directory and type:

grails stop-app

This will stop the application if it is running in forked mode. You can then go to the same URL and see that the page won't be displayed, i.e., the server has been stopped as it will be specified also when the command executes.


grails exit

This will stop the application if running in non-forked mode, otherwise it will quit the console.


grails quit

Exits the console.

Kailey answered 10/1, 2014 at 6:51 Comment(0)
E
6

in Grails 2.3.3, running 'grails dev run-app' on the command line leaves the command window in a kind-of limbo. It does not give you back the command prompt, Ctrl-C does nothing, and you have to revert to killing the processes by hand.

It is much more pleasant to follow the intended usage, as follows:

  1. On the command line, enter the command 'grails' and hit return (notice no parameters are given). This starts grails itself, (and only grails, i.e. it does not start your server or app). This results in one new java process. It also gives you back the grails prompt, so you are still in control.

1.1 At the grails prompt, you can start your server (and app), by typing 'run-app'. This starts your server (in dev mode), and again gives you back the grails prompt. With your server running, you now have two java processes running, one for grails, and the other for your server and app.

1.2 If you want to stop your server (and app), you can, at the grails prompt, enter 'stop-app', which will stop the server and app. Also, you get your grails prompt back. After stopping your server/app, you will be back to having just one java process running, i.e. grails.

1.3 At the grails prompt, you can start and stop your app as many times as you like.

1.4 To stop grails itself, at the grails prompt, you can enter 'exit' or 'quit', and then grails will quit, and leave you back with the normal command prompt. At this point, the grails java process should be gone too, so there should be no java processes running.

I believe all of grails 2.3.x behaves like this. My system is windows 7.

Hope this helps. Noel

Equinoctial answered 23/12, 2013 at 12:21 Comment(0)
F
3

In Grails 2.1.0, a simple "exit" stops the server

Funicular answered 1/8, 2012 at 7:39 Comment(0)
T
1

I found a neat way that works on Grails 2.0.1 for me.

This is a hack that uses a hack put in GrailsRun.groovy for shutting down servers after running functional tests. (see line 246)

Create a file in the application basedir named .kill-run-app

When Grails sees the .kill-run-app file, it issues a grailsServer.stop(). It also conveniently deletes the file. This may depend on having autoRecompile on. I'm not sure, like I said this is a hack.

One day it will most likely cease to work when the GrailsRun.groovy script is changed.

I created a simple Ant target to do this. Granted you will need another terminal to execute it (actually I run it from Eclipse).

<target name="kill-app" description="--> Kills Grails web application" depends="">
  <touch file="${basedir}/.kill-run-app"/>
</target>
Talon answered 7/5, 2012 at 14:20 Comment(0)
D
0

Quick way is to kill the java process:

ps -aux | grep grails

kill "proess ID from above that is container to your application"

Debbi answered 9/3, 2012 at 10:52 Comment(0)
R
0

I'm new to Grails and I also had this "problem". I wrote a little script (called grill ;-)) that kills all the grails-processes.

#!/bin/bash
for P in $(ps aux | grep grails | grep java | awk '{print $2};'); do
kill -9 $P
done
exit 0
Roca answered 4/10, 2013 at 6:58 Comment(0)
C
0

I had same problem to stop my running grails server. I did

  1. ps aux | grep grails --> that gave me the PID
  2. kill -9 PID

That way I was able to stop my running server. Hope that helps.

Coroneted answered 27/2, 2017 at 4:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.