#!/bin/bash
nohup java -jar target/zplxjj.jar &
複製代碼
#!/bin/bash
PID=$(ps -ef | grep target/zplxjj.jar | grep -v grep | awk '{ print $2 }')
if [ -z "$PID" ]
then
echo Application is already stopped
else
echo kill $PID
kill $PID
fi
~
複製代碼
#!/bin/bash
echo stop application
source stop.sh
echo start application
source start.sh
複製代碼
啓動本身的項目只須要執行run.sh就行,一個本身的spring boot就搭建起來了php
實際項目中,咱們但願日誌能夠記錄在服務器上面,這邊用的是logback,是springboot自帶的,我這邊集成方式是加入logback-spring.xml文件,加入後啓動項目便可,文件內容以下:java
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!--用來定義變量值的標籤-->
<property name="LOG_HOME" value="./logs"/>
<property name="encoding" value="UTF-8"/>
<!--格式化輸出:%d表示日期,%thread表示線程名,%-5level:級別從左顯示5個字符寬度;%M:%L是方法和行號;%msg是日誌消息;%n是換行符-->
<property name="normal-pattern" value="%d{yyyy-MM-dd/HH:mm:ss.SSS}|%X{localIp}|%X{requestId}|%X{requestSeq}|%X{country}|%X{deviceType}|%X{deviceId}|%X{userId}|^_^|[%t] %-5level %logger{50} %line - %m%n"/>
<property name="plain-pattern" value="%d{yyyy-MM-dd.HH:mm:ss} %msg%n"/>
<!-- 按照天天生成日誌文件 -->
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!--日誌文件輸出的文件名-->
<file>${LOG_HOME}/zplxjj.log</file>
<Append>true</Append>
<prudent>false</prudent>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${normal-pattern}</pattern>
<charset>${encoding}</charset>
</encoder>
<!--按時間分割-->
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/zplxjj.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>128MB</maxFileSize>
<maxHistory>15</maxHistory>
<totalSizeCap>32GB</totalSizeCap>
</rollingPolicy>
</appender>
<!--控制檯輸出-->
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<!--格式化輸出:%d表示日期,%thread表示線程名,%-5level:級別從左顯示5個字符寬度%msg:日誌消息,%n是換行符-->
<pattern>${normal-pattern}</pattern>
</encoder>
</appender>
<!-- log file error -->
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<file>${LOG_HOME}/zplxjj-error.log</file>
<prudent>false</prudent>
<Append>true</Append>
<encoder>
<pattern>${normal-pattern}</pattern>
<charset>${encoding}</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/zplxjj-error.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
<maxFileSize>128MB</maxFileSize>
<maxHistory>15</maxHistory>
<totalSizeCap>32GB</totalSizeCap>
</rollingPolicy>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT"/>
<appender-ref ref="FILE"/>
<appender-ref ref="ERROR"/>
</root>
</configuration>
複製代碼
效果如圖:spring
本人也開通了微信公衆號:stonezplxjj和我的博客:www.zplxjj.com,更多文章歡迎關注公衆號:springboot