Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop a spring boot service from command line?

I’m a spring-boot newbie, so please go easy on me.

I need to offer a way for an administrator to start and stop my spring-boot microservice from a job scheduler. If I can create start.bat and stop.bat files for the service, then the scheduler could call them.

How do I stop a spring-boot microservice from command line without killing the process? I'd like a graceful exit, if possible.

The host will be a Windows server.

like image 339
Eric Avatar asked Jul 14 '16 14:07

Eric


3 Answers

If you have Spring Boot Actuator included in your project, you can enable a shutdown endpoint (by default it is not enabled). This means that if you make a request to: http://yourserver.com/yourapp/shutdown, the application will shutdown gracefully. An administrator could do such a request using a standard tool such as curl.

See Endpoints in the Spring Boot reference documentation. You can enable the shutdown endpoint by adding the following to your application.properties:

endpoints.shutdown.enabled=true

Ofcourse, you'll want to restrict access to this endpoint, otherwise anyone who has access to the service could do a request and shutdown the application.

like image 121
Jesper Avatar answered Oct 04 '22 10:10

Jesper


In cmd:

netstat -ano | findstr :[port_on_which_app_runs]

then

taskkill /PID [PID_of_the_app] /F

Found here

like image 44
Kaisumaro Avatar answered Oct 04 '22 12:10

Kaisumaro


The easiest way to kill a process using cmd is by typing this single line of command:

> kill $(lsof -t -i:port_num)
like image 44
webcrawler Avatar answered Oct 04 '22 10:10

webcrawler