精品伊人久久大香线蕉,开心久久婷婷综合中文字幕,杏田冲梨,人妻无码aⅴ不卡中文字幕

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
Spring Boot 部署與服務配置

spring Boot 其默認是集成web容器的,啟動方式由像普通Java程序一樣,main函數(shù)入口啟動。其內(nèi)置Tomcat容器或Jetty容器,具體由配置來決定(默認Tomcat)。當然你也可以將項目打包成war包,放到獨立的web容器中(Tomcat、weblogic等等),當然在此之前你要對程序入口做簡單調(diào)整。

項目構建我們使用Maven或Gradle,這將使項目依賴、jar包管理、以及打包部署變的非常方便。

一、內(nèi)嵌 Server 配置

Spring Boot將容器內(nèi)置后,它通過配置文件的方式類修改相關server配置。
先看一下下面的圖,為關于server的配置列項:


其中常用的配置只有少數(shù)幾個,已經(jīng)用紫色標記起來。紅框圈起來的部分,看名稱分類就可以明白其作用。
對server的幾個常用的配置做個簡單說明:

# 項目contextPath,一般在正式發(fā)布版本中,我們不配置server.context-path=/myspringboot# 錯誤頁,指定發(fā)生錯誤時,跳轉(zhuǎn)的URL。請查看BasicErrorController源碼便知server.error.path=/error# 服務端口server.port=9090# session最大超時時間(分鐘),默認為30server.session-timeout=60# 該服務綁定IP地址,啟動服務器時如本機不是該IP地址則拋出異常啟動失敗,只有特殊需求的情況下才配置# server.address=192.168.16.11
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

Tomcat
Tomcat為Spring Boot的默認容器,下面是幾個常用配置:

# tomcat最大線程數(shù),默認為200server.tomcat.max-threads=800# tomcat的URI編碼server.tomcat.uri-encoding=UTF-8# 存放Tomcat的日志、Dump等文件的臨時文件夾,默認為系統(tǒng)的tmp文件夾(如:C:\Users\Shanhy\AppData\Local\Temp)server.tomcat.basedir=H:/springboot-tomcat-tmp# 打開Tomcat的Access日志,并可以設置日志格式的方法:#server.tomcat.access-log-enabled=true#server.tomcat.access-log-pattern=# accesslog目錄,默認在basedir/logs#server.tomcat.accesslog.directory=# 日志文件目錄logging.path=H:/springboot-tomcat-tmp# 日志文件名稱,默認為spring.loglogging.file=myapp.log
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

Jetty
如果你要選擇Jetty,也非常簡單,就是把pom中的tomcat依賴排除,并加入Jetty容器的依賴,如下:

<dependencies>  <dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-web</artifactId>    <exclusions>      <exclusion>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-tomcat</artifactId>      </exclusion>    </exclusions>  </dependency>  <dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-jetty</artifactId>  </dependency><dependencies> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

打包
打包方法:
CMD進入項目目錄,使用 mvn clean package 命令打包,以我的項目工程為例:

E:\spring-boot-sample>mvn clean package
  • 1
  • 1

可以追加參數(shù) -Dmaven.test.skip=true 跳過測試。
打包后的文件存放于項目下的target目錄中,如:spring-boot-sample-0.0.1-SNAPSHOT.jar
如果pom配置的是war包,則為spring-boot-sample-0.0.1-SNAPSHOT.war

二、部署到JavaEE容器

  1. 修改啟動類,繼承 SpringBootServletInitializer 并重寫 configure 方法
public class SpringBootSampleApplication extends SpringBootServletInitializer{    private static final Logger logger = LoggerFactory.getLogger(SpringBootSampleApplication.class);    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {        return builder.sources(this.getClass());    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  1. 修改pom文件中jar 為 war
<!-- <packaging>jar</packaging> --><packaging>war</packaging>
  • 1
  • 2
  • 1
  • 2
  1. 修改pom,排除tomcat插件
        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>            <exclusions>                <exclusion>                    <groupId>org.springframework.boot</groupId>                    <artifactId>spring-boot-starter-tomcat</artifactId>                </exclusion>            </exclusions>        </dependency>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  1. 打包部署到容器
    使用命令 mvn clean package 打包后,同一般J2EE項目一樣部署到web容器。

三、使用Profile區(qū)分環(huán)境

spring boot 可以在 “配置文件”、“Java代碼類”、“日志配置” 中來配置profile區(qū)分不同環(huán)境執(zhí)行不同的結果

1、配置文件
使用配置文件application.yml 和 application.properties 有所區(qū)別
以application.properties 為例,通過文件名來區(qū)分環(huán)境 application-{profile}.properties
application.properties

app.name=MyAppserver.port=8080spring.profiles.active=dev
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

application-dev.properties

server.port=8081
  • 1
  • 1

application-stg.properties

server.port=8082
  • 1
  • 1

在啟動程序的時候通過添加 –spring.profiles.active={profile} 來指定具體使用的配置
例如我們執(zhí)行 java -jar demo.jar –spring.profiles.active=dev 那么上面3個文件中的內(nèi)容將被如何應用?
Spring Boot 會先加載默認的配置文件,然后使用具體指定的profile中的配置去覆蓋默認配置。

app.name 只存在于默認配置文件 application.properties 中,因為指定環(huán)境中不存在同樣的配置,所以該值不會被覆蓋
server.port 默認為8080,但是我們指定了環(huán)境后,將會被覆蓋。如果指定stg環(huán)境,server.port 則為 8082
spring.profiles.active 默認指定dev環(huán)境,如果我們在運行時指定 –spring.profiles.active=stg 那么將應用stg環(huán)境,最終 server.port 的值為8082

2、Java類中@Profile注解
下面2個不同的類實現(xiàn)了同一個接口,@Profile注解指定了具體環(huán)境

// 接口定義public interface SendMessage {    // 發(fā)送短信方法定義    public void send();}// Dev 環(huán)境實現(xiàn)類@Component@Profile("dev")public class DevSendMessage implements SendMessage {    @Override    public void send() {        System.out.println(">>>>>>>>Dev Send()<<<<<<<<");    }}// Stg環(huán)境實現(xiàn)類@Component@Profile("stg")public class StgSendMessage implements SendMessage {    @Override    public void send() {        System.out.println(">>>>>>>>Stg Send()<<<<<<<<");    }}// 啟動類@SpringBootApplicationpublic class ProfiledemoApplication {    @Value("${app.name}")    private String name;    @Autowired    private SendMessage sendMessage;    @PostConstruct    public void init(){        sendMessage.send();// 會根據(jù)profile指定的環(huán)境實例化對應的類    }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48

3、logback-spring.xml也支持有節(jié)點來支持區(qū)分

<?xml version="1.0" encoding="UTF-8"?><configuration>    <include resource="org/springframework/boot/logging/logback/base.xml" />    <logger name="org.springframework.web" level="INFO"/>    <springProfile name="default">        <logger name="org.springboot.sample" level="TRACE" />    </springProfile>    <springProfile name="dev">        <logger name="org.springboot.sample" level="DEBUG" />    </springProfile>    <springProfile name="staging">        <logger name="org.springboot.sample" level="INFO" />    </springProfile></configuration>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

再說一遍文件名不要用logback.xml 請使用logback-spring.xml

四、指定外部的配置文件

有些系統(tǒng),關于一些數(shù)據(jù)庫或其他第三方賬戶等信息,由于安全問題,其配置并不會提前配置在項目中暴露給開發(fā)人員。
對于這種情況,我們在運行程序的時候,可以通過參數(shù)指定一個外部配置文件。
以 demo.jar 為例,方法如下:

java -jar demo.jar --spring.config.location=/opt/config/application.properties
  • 1
  • 1

其中文件名隨便定義,無固定要求。

五、創(chuàng)建一個Linux 應用的sh腳本

下面幾個腳本僅供參考,請根據(jù)自己需要做調(diào)整
start.sh

#!/bin/shrm -f tpidnohup java -jar myapp.jar --spring.config.location=application.yml > /dev/null 2>&1 &echo $! > tpidecho Start Success!
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

stop.sh

#!/bin/shAPP_NAME=myapptpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`if [ ${tpid} ]; then    echo 'Stop Process...'    kill -15 $tpidfisleep 5tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`if [ ${tpid} ]; then    echo 'Kill Process!'    kill -9 $tpidelse    echo 'Stop Success!'fi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

check.sh

#!/bin/shAPP_NAME=myapptpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`if [ ${tpid} ]; then        echo 'App is running.'else        echo 'App is NOT running.'fi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

kill.sh

#!/bin/shAPP_NAME=myapptpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`if [ ${tpid} ]; then    echo 'Kill Process!'    kill -9 $tpidfi
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8spring Boot 其默認是集成web容器的,啟動方式由像普通Java程序一樣,main函數(shù)入口啟動。其內(nèi)置Tomcat容器或Jetty容器,具體由配置來決定(默認Tomcat)。當然你也可以將項目打包成war包,放到獨立的web容器中(Tomcat、weblogic等等),當然在此之前你要對程序入口做簡單調(diào)整。

    項目構建我們使用Maven或Gradle,這將使項目依賴、jar包管理、以及打包部署變的非常方便。

    一、內(nèi)嵌 Server 配置

    Spring Boot將容器內(nèi)置后,它通過配置文件的方式類修改相關server配置。
    先看一下下面的圖,為關于server的配置列項:


    其中常用的配置只有少數(shù)幾個,已經(jīng)用紫色標記起來。紅框圈起來的部分,看名稱分類就可以明白其作用。
    對server的幾個常用的配置做個簡單說明:

    # 項目contextPath,一般在正式發(fā)布版本中,我們不配置server.context-path=/myspringboot# 錯誤頁,指定發(fā)生錯誤時,跳轉(zhuǎn)的URL。請查看BasicErrorController源碼便知server.error.path=/error# 服務端口server.port=9090# session最大超時時間(分鐘),默認為30server.session-timeout=60# 該服務綁定IP地址,啟動服務器時如本機不是該IP地址則拋出異常啟動失敗,只有特殊需求的情況下才配置# server.address=192.168.16.11
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    Tomcat
    Tomcat為Spring Boot的默認容器,下面是幾個常用配置:

    # tomcat最大線程數(shù),默認為200server.tomcat.max-threads=800# tomcat的URI編碼server.tomcat.uri-encoding=UTF-8# 存放Tomcat的日志、Dump等文件的臨時文件夾,默認為系統(tǒng)的tmp文件夾(如:C:\Users\Shanhy\AppData\Local\Temp)server.tomcat.basedir=H:/springboot-tomcat-tmp# 打開Tomcat的Access日志,并可以設置日志格式的方法:#server.tomcat.access-log-enabled=true#server.tomcat.access-log-pattern=# accesslog目錄,默認在basedir/logs#server.tomcat.accesslog.directory=# 日志文件目錄logging.path=H:/springboot-tomcat-tmp# 日志文件名稱,默認為spring.loglogging.file=myapp.log
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    Jetty
    如果你要選擇Jetty,也非常簡單,就是把pom中的tomcat依賴排除,并加入Jetty容器的依賴,如下:

    <dependencies>  <dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-web</artifactId>    <exclusions>      <exclusion>        <groupId>org.springframework.boot</groupId>        <artifactId>spring-boot-starter-tomcat</artifactId>      </exclusion>    </exclusions>  </dependency>  <dependency>    <groupId>org.springframework.boot</groupId>    <artifactId>spring-boot-starter-jetty</artifactId>  </dependency><dependencies> 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16

    打包
    打包方法:
    CMD進入項目目錄,使用 mvn clean package 命令打包,以我的項目工程為例:

    E:\spring-boot-sample>mvn clean package
    • 1
    • 1

    可以追加參數(shù) -Dmaven.test.skip=true 跳過測試
    打包后的文件存放于項目下的target目錄中,如:spring-boot-sample-0.0.1-SNAPSHOT.jar
    如果pom配置的是war包,則為spring-boot-sample-0.0.1-SNAPSHOT.war

    二、部署到JavaEE容器

    1. 修改啟動類,繼承 SpringBootServletInitializer 并重寫 configure 方法
    public class SpringBootSampleApplication extends SpringBootServletInitializer{    private static final Logger logger = LoggerFactory.getLogger(SpringBootSampleApplication.class);    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {        return builder.sources(this.getClass());    }}
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    1. 修改pom文件中jar 為 war
    <!-- <packaging>jar</packaging> --><packaging>war</packaging>
    • 1
    • 2
    • 1
    • 2
    1. 修改pom,排除tomcat插件
            <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>            <exclusions>                <exclusion>                    <groupId>org.springframework.boot</groupId>                    <artifactId>spring-boot-starter-tomcat</artifactId>                </exclusion>            </exclusions>        </dependency>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    1. 打包部署到容器
      使用命令 mvn clean package 打包后,同一般J2EE項目一樣部署到web容器。

    三、使用Profile區(qū)分環(huán)境

    spring boot 可以在 “配置文件”、“Java代碼類”、“日志配置” 中來配置profile區(qū)分不同環(huán)境執(zhí)行不同的結果

    1、配置文件
    使用配置文件application.yml 和 application.properties 有所區(qū)別
    以application.properties 為例,通過文件名來區(qū)分環(huán)境 application-{profile}.properties
    application.properties

    app.name=MyAppserver.port=8080spring.profiles.active=dev
    • 1
    • 2
    • 3
    • 1
    • 2
    • 3

    application-dev.properties

    server.port=8081
    • 1
    • 1

    application-stg.properties

    server.port=8082
    • 1
    • 1

    在啟動程序的時候通過添加 –spring.profiles.active={profile} 來指定具體使用的配置
    例如我們執(zhí)行 java -jar demo.jar –spring.profiles.active=dev 那么上面3個文件中的內(nèi)容將被如何應用?
    Spring Boot 會先加載默認的配置文件,然后使用具體指定的profile中的配置去覆蓋默認配置。

    app.name 只存在于默認配置文件 application.properties 中,因為指定環(huán)境中不存在同樣的配置,所以該值不會被覆蓋
    server.port 默認為8080,但是我們指定了環(huán)境后,將會被覆蓋。如果指定stg環(huán)境,server.port 則為 8082
    spring.profiles.active 默認指定dev環(huán)境,如果我們在運行時指定 –spring.profiles.active=stg 那么將應用stg環(huán)境,最終 server.port 的值為8082

    2、Java類中@Profile注解
    下面2個不同的類實現(xiàn)了同一個接口,@Profile注解指定了具體環(huán)境

    // 接口定義public interface SendMessage {    // 發(fā)送短信方法定義    public void send();}// Dev 環(huán)境實現(xiàn)類@Component@Profile("dev")public class DevSendMessage implements SendMessage {    @Override    public void send() {        System.out.println(">>>>>>>>Dev Send()<<<<<<<<");    }}// Stg環(huán)境實現(xiàn)類@Component@Profile("stg")public class StgSendMessage implements SendMessage {    @Override    public void send() {        System.out.println(">>>>>>>>Stg Send()<<<<<<<<");    }}// 啟動類@SpringBootApplicationpublic class ProfiledemoApplication {    @Value("${app.name}")    private String name;    @Autowired    private SendMessage sendMessage;    @PostConstruct    public void init(){        sendMessage.send();// 會根據(jù)profile指定的環(huán)境實例化對應的類    }}
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48

    3、logback-spring.xml也支持有節(jié)點來支持區(qū)分

    <?xml version="1.0" encoding="UTF-8"?><configuration>    <include resource="org/springframework/boot/logging/logback/base.xml" />    <logger name="org.springframework.web" level="INFO"/>    <springProfile name="default">        <logger name="org.springboot.sample" level="TRACE" />    </springProfile>    <springProfile name="dev">        <logger name="org.springboot.sample" level="DEBUG" />    </springProfile>    <springProfile name="staging">        <logger name="org.springboot.sample" level="INFO" />    </springProfile></configuration>
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    再說一遍文件名不要用logback.xml 請使用logback-spring.xml

    四、指定外部的配置文件

    有些系統(tǒng),關于一些數(shù)據(jù)庫或其他第三方賬戶等信息,由于安全問題,其配置并不會提前配置在項目中暴露給開發(fā)人員。
    對于這種情況,我們在運行程序的時候,可以通過參數(shù)指定一個外部配置文件。
    以 demo.jar 為例,方法如下:

    java -jar demo.jar --spring.config.location=/opt/config/application.properties
    • 1
    • 1

    其中文件名隨便定義,無固定要求。

    五、創(chuàng)建一個Linux 應用的sh腳本

    下面幾個腳本僅供參考,請根據(jù)自己需要做調(diào)整
    start.sh

    #!/bin/shrm -f tpidnohup java -jar myapp.jar --spring.config.location=application.yml > /dev/null 2>&1 &echo $! > tpidecho Start Success!
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    stop.sh

    #!/bin/shAPP_NAME=myapptpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`if [ ${tpid} ]; then    echo 'Stop Process...'    kill -15 $tpidfisleep 5tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`if [ ${tpid} ]; then    echo 'Kill Process!'    kill -9 $tpidelse    echo 'Stop Success!'fi
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18

    check.sh

    #!/bin/shAPP_NAME=myapptpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`if [ ${tpid} ]; then        echo 'App is running.'else        echo 'App is NOT running.'fi
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    kill.sh

    #!/bin/shAPP_NAME=myapptpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`if [ ${tpid} ]; then    echo 'Kill Process!'    kill -9 $tpidfi
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
把spring
spring boot 項目部署到服務器 兩種方式
登頂 Github 的 Spring Boot 倉庫!艿艿寫的最肝系列~
Spring Boot 配置優(yōu)先級順序
Spring Boot :Undertow
Springboot使用Undertow
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服

主站蜘蛛池模板: 五常市| 泰宁县| 江津市| 广水市| 克拉玛依市| 绵阳市| 张家港市| 句容市| 广州市| 宽甸| 毕节市| 鄱阳县| 宜昌市| 甘泉县| 山东省| 谢通门县| 沈阳市| 武夷山市| 马尔康县| 玉门市| 武安市| 崇礼县| 旌德县| 揭东县| 天全县| 三台县| 汤阴县| 随州市| 芜湖市| 石狮市| 五台县| 铁岭市| 突泉县| 河西区| 乐山市| 明光市| 克东县| 阳原县| 囊谦县| 广汉市| 抚远县|