从脚本启动Spring Boot应用程序 [英] Starting Spring boot applications from script

查看:76
本文介绍了从脚本启动Spring Boot应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用正常的spring mvn命令,我可以从命令行启动spring boot应用程序,并使用Control + c终止它.但是,我创建了一堆服务,稍后将对其进行dockerize.目前,它们是mvn生成的普通Java jar文件.如何使用python脚本或Bash脚本一个一个地启动它们,然后使用脚本终止它们.有什么方法可以启动它并且脚本不会被阻止,并且该应用程序将具有一个名称,以后我可以使用它来停止该应用程序?

Using normal spring mvn commands, I can start a spring boot application from command line and terminate it with Control+c. I however have created a bunch of services which I will dockerize later. For now they are plain java jar files generated by mvn. How do I use a python script or a Bash script to start them one by one and then use a script to terminate them. Is there some way where i start it and script won't block and the app will have a name that i can later use to stop the app?

推荐答案

我会遵循

I would follow the documentation to install Spring-Boot application as a Unix/Linux service.

所有您需要做的就是将此依赖项添加到您的 pom.xml :

All you have to do is to add this dependency to your pom.xml:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <executable>true</executable>
    </configuration>
</plugin>

添加插件后,您应该安装并创建指向应用程序的符号链接(

After adding the plugin you should install and create a symlink to your application (exact part of documentation):

假设您已在其中安装了Spring Boot应用程序/var/myapp ,用于将Spring Boot应用程序安装为init.d服务只需创建一个符号链接:

Assuming that you have a Spring Boot application installed in /var/myapp, to install a Spring Boot application as an init.d service simply create a symlink:

$ sudo ln -s/var/myapp/myapp.jar/etc/init.d/myapp

一旦安装,您可以按照通常的方式启动和停止服务.例如,在基于Debian的系统:

Once installed, you can start and stop the service in the usual way. For example, on a Debian based system:

$ service myapp start

然后,您可以创建一个bash脚本,以一种干净的方式 start stop restart .

Then you are able to create a bash script to start, stop or restart your applications in a clean way.

这篇关于从脚本启动Spring Boot应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆