3

I need to gracefully start and shutdown the spring boot application using a script . Is there any other way to do it except using an actuator module in the application. Currently i have to stop the spring boot process manually in the task manager.

sergionni
  • 13,290
  • 42
  • 132
  • 189
Anu Raman
  • 53
  • 1
  • 2
  • 5
  • do you want to handle the stop of the application or should the application stop after finishing the code? – Patrick Feb 26 '16 at 07:50
  • 1
    Possible duplicate of [How to gracefully shutdown embeded jetty](http://stackoverflow.com/questions/30347144/how-to-gracefully-shutdown-embeded-jetty) – Serge Ballesta Feb 26 '16 at 08:11
  • How do you start your app exactly? – Stephane Nicoll Feb 26 '16 at 09:10
  • 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) – Stewart Mar 15 '17 at 19:09
  • try this for graceful starting and stopping of the applications via shell script and pid file: https://stackoverflow.com/questions/26547532/how-to-shutdown-a-spring-boot-application-in-a-correct-way/51426095#51426095 – Anand Varkey Philips Jul 19 '18 at 15:20

1 Answers1

2

Ultimately the spring boot application spins off a java process which needs to be killed. At present you are killing it manually.

You have a few options:

  1. You can use SpringApplication.exit(ApplicationContext, ExitCodeGenerator...) method.
  2. If your application is not a long running application then do you have some exit point where your application should stop. At that point you can System.exit(0)
  3. You can use external manager tools, for example on unix you can use supervisor, here is a blog you can read about this.
  4. SpringApplication.run gives you ApplicationContext which you can close.
Sandeep B
  • 765
  • 1
  • 6
  • 19
  • try this for graceful starting and stopping of the applications via shell script and pid file: https://stackoverflow.com/questions/26547532/how-to-shutdown-a-spring-boot-application-in-a-correct-way/51426095#51426095 – Anand Varkey Philips Jul 19 '18 at 15:18