Linux shell command to start, stop(kill) or restart springboot executable jar applications
1. The purpose of this post
Sometimes, we package Spring Boot applications as a single executable jar file and deploy it to a server. We start the jar as follows:
However, when we want to stop or restart it, we need to perform the following steps:
This process can be cumbersome. Today, I will demonstrate Linux shell commands to kill or restart Spring Boot executable jar applications, allowing you to use a single command to manage your app.
2. Environments
- Spring Boot 1.x or 2.x
3. The commands
3.1 Kill the Spring Boot App
If your Spring Boot jar file name is myapp-exec.jar, you can kill it using this command:
Save the above script as stop.sh.
3.2 Start the Spring Boot App in the background
To start the app in the background, you can use the nohup
command:
Save the above script as start.sh.
3.3 Restart the Spring Boot App
Now, you can create a file named restart.sh to handle the restart process:
Save the above script as restart.sh.
Summary
This post provides a quick and efficient way to manage Spring Boot applications deployed as executable jar files on Linux servers. By using the provided shell scripts, you can easily start, stop, or restart your application with a single command. This approach saves time and reduces the complexity of managing Spring Boot applications in a production environment.
Final Words + More Resources
My intention with this article was to help others who might be considering solving such a problem. So I hope that’s been the case here. If you still have any questions, don’t hesitate to ask me by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!