springboot jar 作为Wrapper Service服务启动-Linux
同步Windows版本教程参考:https://blog.****.net/github_33809414/article/details/87192718
此教程为Linux上将springboot jar作为服务启动, 版本:springboot-2.1.2RELEASE。
该服务中web程序的context-path、port都会以springboot中配置的为准。
- 下载Java Service Wrapper。目前最新版本为:3.5.37。选择自己对应的操作系统和位数,一般是Linux+x86 cpu。
- 修改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
- 修改bin/testwrapper
- 在bin目录下执行
启动服务:./testwrapper start
停止服务:./testwrapper stop
重启服务:./testwrapper restart
最后:服务不是免费的
参考
https://blog.****.net/myvernal/article/details/79104026
https://my.oschina.net/u/3866531/blog/1845669/
https://blog.****.net/sq287197314/article/details/82996012