安装Spring Boot应用程序 – 参考官网教程

1. 修改logback-spring.xml文件的log路径

spring_boot

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_TEMP" value="/var/tomcat/testApp6097/logs/"/>
<property name="folder" value="/var/tomcat/testApp6097/logs/"/>

<springProfile name="dev">
<property name="folder" value="./logs/"/>
<logger name="org.springframework" level="info"/>
</springProfile>

<springProfile name="test">
<property name="folder" value="/var/tomcat/testApp6097/logs/"/>
<logger name="org.springframework" level="info"/>
</springProfile>

<!-- 彩色日志依赖的渲染类 -->
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />

<!--
<include resource="org/springframework/boot/logging/logback/base.xml"/>
-->

<logger name="org.hibernate" level="ERROR"/>

<appender name="ROLLIN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${folder}/test-app.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>${folder}/test-app.%d{yyyy-MM-dd}.log</fileNamePattern>

<!-- keep 60 days worth of history capped at 3GB total size -->
<maxHistory>60</maxHistory>
<!--<totalSizeCap>3GB</totalSizeCap>-->

</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %clr(%5.5level) - [%15.15thread] %clr(%-40.40logger){cyan}%clr([%3.-5line]){magenta} :%M %msg%n</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="ROLLIN"/>
</root>

</configuration>

2. 在myapp.jar当前目录下创建conf文件myapp.conf同名不同辍, 输入以下参考内容

JAVA_OPTS="-Xms256m -Xmx768m"
LOG_FOLDER=/var/tomcat/testApp6096/logs

3. 创建Service软连接

sudo ln -s /var/tomcat/myapp.jar /etc/init.d/test-app

#这里的test-app名字与日志test-app.log名字保持一致,打印日志才能打印到同一个文件中

4. 设置运行文件权限

chmod 500 myapp.jar

chmod 400 myapp.conf
sudo chown root:root myapp.conf

5. 启动, 停止, 状态

sudo /etc/init.d/test-app start
sudo /etc/init.d/test-app stop
sudo /etc/init.d/test-app status

6. 设置开机自动启动程序

sudo update-rc.d test-app defaults

7. 移除开机自动启动

sudo update-rc.d -f test-app remove

查看Java运行程序进程

ps -ef|grep java
滚动至顶部