Starting Spring boot applications from script

前端 未结 4 1006
醉梦人生
醉梦人生 2021-01-17 04:28

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

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-17 04:58

    You could use a script to achieve this. For example a startup.sh may look like this. It will start the application and write the process id to /path/to/app/pid.file

    #!/bin/bash
    nohup java -jar /path/to/app/hello-world.jar > /path/to/log.txt 2>&1 &
    echo $! > /path/to/app/pid.file
    

    And a shutdown.sh may look like this.

    #!/bin/bash
    kill $(cat /path/to/app/pid.file)
    

    You can find more detail in my post. https://springhow.com/start-stop-scripts-for-spring-boot-applications/

提交回复
热议问题