SpringBoot jar包作爲Wrapper服務啓動-Linux

同步Windows版本教程參考:https://blog.csdn.net/github_33809414/article/details/87192718
此教程爲Linux上將springboot jar作爲服務啓動, 版本:springboot-2.1.2RELEASE。
該服務中web程序的context-path、port都會以springboot中配置的爲準。

  1. 下載Java Service Wrapper。目前最新版本爲:3.5.37。選擇自己對應的操作系統和位數,一般是Linux+x86 cpu。
  2. 修改conf/wrapper.conf文件,最好先備份
#encoding=UTF-8

##不知道爲啥,這句去掉就不能啓動服務
#include ../conf/wrapper-license.conf

#Specify the language and locale which the Wrapper should use.
#需要取消註釋,否則會去找wrapperjni_zh.mo文件,但是../lang/中沒有該文件
wrapper.lang=en_US # en_US or ja_JP
wrapper.lang.folder=../lang

#Java Application
set.JAVA_HOME=/usr/local/java/jdk1.8.0_191
wrapper.java.command=%JAVA_HOME%/bin/java

#Java Library Path (location of Wrapper.DLL or libwrapper.so)
wrapper.java.library.path.1=../lib

#Tell the Wrapper to log the full generated Java command line.
#wrapper.java.command.loglevel=INFO

#老版本寫法
#wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperStartStopApp
wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp

#Java Classpath (include wrapper.jar)  Add class path elements as needed starting from 1
#自己的jar包路徑
wrapper.java.classpath.1=../lib/boot.jar
wrapper.java.classpath.2=../lib/wrapper.jar

#Java Bits.  On applicable platforms, tells the JVM to run in 32 or 64-bit mode.
wrapper.java.additional.auto_bits=TRUE

#Java Additional Parameters
wrapper.java.additional.1=

#Initial Java Heap Size (in MB)
#wrapper.java.initmemory=3

#Maximum Java Heap Size (in MB)
#wrapper.java.maxmemory=64

#Application parameters.  Add parameters as needed starting from 1
wrapper.app.parameter.1=org.springframework.boot.loader.JarLauncher
#如果代碼包與依賴jar包分開打包也可以直接寫main所在的入口類
#wrapper.app.parameter.1=com.ysl.springboot.SpringbootApplication

#Enables Debug output from the Wrapper.
#wrapper.debug=TRUE

#Format of output for the console.  (See docs for formats)
#wrapper.console.format=PM
wrapper.console.format=LPDTM

#Log Level for console output.  (See docs for log levels)
wrapper.console.loglevel=INFO

#Log file to use for wrapper output logging.
#wrapper.logfile=../logs/wrapper.log
#wrapper 日誌
wrapper.logfile=../logs/boot_YYYYMMDD.log
wrapper.logfile.rollmode=DATE

#Format of output for the log file.  (See docs for formats)
#wrapper.logfile.format=LPTM
wrapper.logfile.format=LPDTM

#Log Level for log file output.  (See docs for log levels)
wrapper.logfile.loglevel=INFO

#Maximum size that the log file will be allowed to grow to before
#the log is rolled. Size is specified in bytes.  The default value
#of 0, disables log rolling.  May abbreviate with the 'k' (kb) or
#'m' (mb) suffix.  For example: 10m = 10 megabytes.
wrapper.logfile.maxsize=0

#Maximum number of rolled log files which will be allowed before old
#files are deleted.  The default value of 0 implies no limit.
wrapper.logfile.maxfiles=0

#Log Level for sys/event log output.  (See docs for log levels)
wrapper.syslog.loglevel=NONE

#Allow for the use of non-contiguous numbered properties
wrapper.ignore_sequence_gaps=TRUE

#Do not start if the pid file already exists.
wrapper.pidfile.strict=TRUE

#Title to use when running as a console  app.name in bin/testwrapper
[email protected]@

#********************************************************************
#Wrapper JVM Checks
#********************************************************************
#Detect DeadLocked Threads in the JVM. (Requires Standard Edition)
wrapper.check.deadlock=TRUE
wrapper.check.deadlock.interval=10
wrapper.check.deadlock.action=RESTART
wrapper.check.deadlock.output=FULL

#Out Of Memory detection.
#(Ignore output from dumping the configuration to the console.  This is only needed by the TestWrapper sample application.)
wrapper.filter.trigger.999=wrapper.filter.trigger.*java.lang.OutOfMemoryError
wrapper.filter.allow_wildcards.999=TRUE
wrapper.filter.action.999=NONE
#Ignore -verbose:class output to avoid false positives.
wrapper.filter.trigger.1000=[Loaded java.lang.OutOfMemoryError
wrapper.filter.action.1000=NONE
#(Simple match)
wrapper.filter.trigger.1001=java.lang.OutOfMemoryError
#(Only match text in stack traces if -XX:+PrintClassHistogram is being used.)
#wrapper.filter.trigger.1001=Exception in thread "*" java.lang.OutOfMemoryError
#wrapper.filter.allow_wildcards.1001=TRUE
wrapper.filter.action.1001=RESTART
wrapper.filter.message.1001=The JVM has run out of memory.

#Specify custom mail content
wrapper.event.jvm_restart.email.body=The JVM was restarted.\n\nPlease check on its status.\n

#Name of the service. 
[email protected]@

#Display name of the service		 app.long.name in bin/testwrapper
[email protected]@

#Description of the service
wrapper.description=Test Wrapper boot-Application Description

#Service dependencies.  Add dependencies as needed starting from 1
wrapper.ntservice.dependency.1=

#Mode in which the service is installed.  AUTO_START, DELAY_START or DEMAND_START
wrapper.ntservice.starttype=AUTO_START

#Allow the service to interact with the desktop (Windows NT/2000/XP only).
wrapper.ntservice.interactive=FALSE

wrapper.ping.timeout=120
  1. 修改bin/testwrapper
    在這裏插入圖片描述
  2. 在bin目錄下執行
    啓動服務:./testwrapper start
    停止服務:./testwrapper stop
    重啓服務:./testwrapper restart

最後:服務不是免費的
在這裏插入圖片描述

參考
https://blog.csdn.net/myvernal/article/details/79104026
https://my.oschina.net/u/3866531/blog/1845669/
https://blog.csdn.net/sq287197314/article/details/82996012

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章