How to use command to shutdown grails run-app - grails

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

For Stop Server
Exit from the terminal and use any one from the commands below:
grails exit
grails stop-app
grails quit

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.

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.

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:
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

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

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>

Quick way is to kill the java process:
ps -aux | grep grails
kill "proess ID from above that is container to your application"

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

I had same problem to stop my running grails server. I did
ps aux | grep grails --> that gave me the PID
kill -9 PID
That way I was able to stop my running server. Hope that helps.

Related

Where to edit grails startup command line in IntelliJ IDEA?

Grails-2.5.0 startup fails if fork mode is disabled.
I've found a workaround at https://jira.grails.org/browse/GRAILS-12129, which says;
Don't use the spring loaded java agent. Removing the following from the command started by IntelliJ is enough
But I cannot find where the command is written.
Run -> Edit Configurations doesn't have any option to disable agent.
Where should I edit?
If you open the run configuration you should see fields like Module, Command Line, VM options and more. So add this to the Command Line field
-noreloading -Ddisable.auto.recompile=true run-app
That should stop Grails from reloading your application.

Grails from command line gets number format exceptions in threads and cannot recover

When running Grails in the Windows Command Prompt in development mode, after invoking run-app, I often get a few NumberFormatExceptions thrown for Threads after making changes to code and saving. This particularly happens when changing conf files or if there is a compile error in my code.
The only way to recover that I've found is to close the command prompt window, open a new one, start Grails again, then issue a stop-app and run-app.
Is there another way?
Text from the command window is below:
| Compiling 1 source files.
grails>
Exception: java.lang.NumberFormatException thrown from the UncaughtExceptionHandler in thread "Thread-14"
Exception: java.lang.NumberFormatException thrown from the UncaughtExceptionHandler in thread "Thread-24"
#BurtBeckwith found the solution to this. It appears to be related to running grails on a Windows development environment. Raised in JIRA: http://jira.grails.org/browse/GRAILS-9356. The issue occurs when you start a DOS command window, type "grails" then within grails, do run-app. The solution is to start the DOS command window and type "grails run-app" together. It runs much more stable like this. Then, closing the command window kills the java.exe task and no need to do a stop-app.

Glassfish 2.1 classpath-prefix or classpath-suffix not loading

Hope you can help me here, I am trying to add some new jars to the classpath of the glasspath, but they just fail to load up.
I am using glassfish 2.1
Here's the snippet when the server is started
-Dcom.sun.aas.ClassPathPrefix=../grops/lib/grops-4.3.5.jar;../grops/lib/iaik_jce_full_3.13.jar;../grops/config
-Dcom.sun.aas.ClassPathSuffix=
-Dcom.sun.aas.ServerClassPath=
Snippet from my domain.xml
java-config classpath-suffix="../grops/lib/grops-4.3.5.jar${path.separator}../grops/lib/iaik_jce_full_3.13.jar${path.separator}../grops/config${path.separator}../grops/lib/zmd-security-LU2.jar${path.separator}../grops/lib/db2jcc.jar${path.separator}../grops/lib/db2jcc_javax.jar${path.separator}..........
I have tried from admin console and also changing directly in domain.xml , they just dont load up and always throw an error java.lang.NoClassDefFoundError
I have solved this by myself, actually whenever we add something to the classpath newly a new command window has to be used to restart the glassfish server:
ex run-->cmd--> cd C:\glassfish\bin
asadmin --> start-domain xxx
This has to be done by closing the previous command window after stopping the server by stop-domain because everytime you run asadmin command, asenv is called which sets the new parameters to the JVM.

Grails 2.3 & GGTS 3.4 stop button not working

How to stop grails processes in GGTS 3.4 with grails 2.3. the stop button of GGTS is not stopping the server running and the java.exe processes are still showing in task manager.
Comment the grails.project.fork = [ .. ] part of your BuildConfig.groovy file.
This part enables running run-app, test-app and war in different threads(so you don't have to stop one to start the other), and it seems ggts isn't successfully destroying the thread right now.
For reference, here is the related issue in the ggts bug tracker https://issuetracker.springsource.com/browse/STS-3522
Can you try to disable the "Keep external Grails running" option in Eclipse Preferences -> Groovy -> Grails -> Grails Launcher?
Unchecking the "Keep external Grails running" does not work for me. What I do is to hit the "Grails Command History" icon and type "stopApp" (or pick stopApp if previously typed). Once this commands finishes executing, then you can stop the Grails application using the stop button.
Using Groovy Grails Tool Suite GGTS 3.4.0 on windows 64x. For my simple projects, the stop button works. For a bigger complex project, it does not. I use the "stop-app" (opposite of "run-app"). See: 2.8 Running an Application in the getting started guide. I think that in older versions of Grails ( < 2.x something) you had to create your own "stop-app" script. I think the newer 2.3.x has it built in.
I am using GGTS 3.5.1, Grails 2.3.8, Java1.7 over Windows configuration the command is works for me "stop-app" and "run-app"

Netbeans and Grails - stop server

What is the correct way to stop the web server for Grails in the Netbeans IDE?
After I Run Project (F6), I have been just rebuilding the project to do this. Is there a better way?
If you look under the output tab you can find the task labelled (run-app) and select the Stop icon (a Red Square with a White dot at the center) to stop the application.
This is not true. Type in your terminal "ps aux | grep grails" then you will see a number associated with the app and type "kill -9 (then the number)" and it will stop all process
There is no special Grails command to stop a running server, so just use whatever Netbeans provides to stop a project that was started from inside the IDE

Resources