最近自己写的小项目发布到linux上总是运行一段时间后关闭,查看日志:

Closing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@707194ba: startup date [Tue Jun 19 16:39:22 CST 2018]; root of context hierarchy
Unregistering JMX-exposed beans on shutdown
 
Unregistering JMX-exposed beans

解决方案
用java -jar XXX.jar >/dev/null 2>&1 &
启动后项目看似脱离终端了,其实还是受终端影响,断开xshell之后,项目过段时间就会挂了。GG。

把启动语句加上nohup后台运行就可以了。
nohup java -jar XXX.jar >/dev/null 2>&1 &

nohup是什么
用途:nohup是linux一个命令,不挂断地运行,或者理解为后台运行。

语法:nohup Command [ Arg … ] [ & ]

无论是否将 nohup 命令的输出重定向到终端,输出都将附加到当前目录的 nohup.out 文件中。

如果当前目录的 nohup.out 文件不可写,输出重定向到 $HOME/nohup.out 文件中。

如果没有文件能创建或打开以用于追加,那么 Command 参数指定的命令不可调用。

退出状态:该命令返回下列出口值:   
  126 可以查找但不能调用 Command 参数指定的命令。   
  127 nohup 命令发生错误或不能查找由 Command 参数指定的命令。   
  否则,nohup 命令的退出状态是 Command 参数指定命令的退出状态

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:22 天前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐