目前,我仅使用过Java的jar包和node.js进行后端服务部署,随着技术的增长,后期会对此文章进行补充!
刚开始在Linux上启动后台服务,看见能够正确运行之后,关掉shll,会发现服务可能突然停止,另外有时候出现服务突然停止。
问题原因
The shell exits by default upon receipt of a SIGHUP. Before exiting, an interactive shell resends the SIGHUP to all jobs, running or stopped. Stopped jobs are sent SIGCONT to ensure that they receive the SIGHUP.
shell退出后会
解决方法
使用nohup
命令,比如:
# 原始的启动jar包
java -jar 1.0.0.jar
# 使用nohub命令启动jar包
nohup java -jar 1.0.0.jar &
# 启动node项目:
npm run prd
# 使用nohub启动node项目
nohub npm run prd &
如果不在尾部加上&
,则会出现下面这种错误:
nohup: ignoring input and appending output to ‘nohup.out’