2

What is the best way to stop a Grails application started with:

nohup java -jar myapp.war --server-port=9090 &
esmiralha
  • 8,903
  • 1
  • 14
  • 19
  • http://stackoverflow.com/questions/20254155/how-to-run-nohup-and-write-its-pid-file-in-a-single-bash-statement first write the pid to a file or something then look at scripting it - take a look at tom cat shutdown.sh script - I think a lot of the init scripts just kill the pid – V H Jul 28 '16 at 16:34
  • Yeah, it makes sense... I was hoping that there was a cleaner way to do it. – esmiralha Jul 28 '16 at 17:17
  • I don't understand? How do you want to exit otherwise? You are launching a java process. You can put the above comment in a script and then call /etc/init.d/whatever stop. As I said take a look at tomcat shutdown script https://github.com/imtiger/Tomcat/blob/master/catalina-home/bin/catalina.sh#L423 you will see it calls catalina.sh as shown this does a kill -0 if it fails it does a kill -9. That's tomcat officially you want to beat that ? – V H Jul 28 '16 at 18:43
  • I was hoping that since it is a Spring Boot app I would be able to enable a shutdown URL or something like that. – esmiralha Aug 02 '16 at 15:23
  • 1
    Hmm did some research and it appears that SpringBoot supports the concept of production-ready endpoints. That's what I wanted to do... http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html – esmiralha Aug 02 '16 at 16:11
  • 1
    Possible duplicate of [How to shutdown a Spring Boot Application in a correct way?](http://stackoverflow.com/questions/26547532/how-to-shutdown-a-spring-boot-application-in-a-correct-way) – esmiralha Aug 02 '16 at 16:28

2 Answers2

0

Get the process ID:

ps -A | grep java

If the process id 3114 for example, then stop the process:

kill 3114

Sometimes, Grails app doesn't kill cleanly, then use:

kill -9 3114

Optionally, in one of your action in the controller, you can simply write:

System.exit()

This is the convenient way to shutdown your Grails application which will properly execute all your Shutdown hooks and will cleanly shutdown your app by preventing memory links, releasing resources, closing any streams extra.

https://stackoverflow.com/a/3716015/2405040

Community
  • 1
  • 1
Shashank Agrawal
  • 21,660
  • 9
  • 71
  • 105
0
killall -9 java

or

 killall -15 java

That's it ! This command sends signals to processes identified by their name.


Why -9 or -15 ?

Because you use nohup which prevents the processes from receiving SIGHUP. So, you must use -15 (SIGTERM) or -9 (SIGKILL) with kill command.

Abdennour TOUMI
  • 64,884
  • 28
  • 201
  • 207