相关文章推荐
坐怀不乱的香蕉  ·  this application ...·  1 年前    · 
逼格高的核桃  ·  fputc ...·  2 年前    · 
内向的黄豆  ·  Propper use of ...·  2 年前    · 

最近在使用ansible shell模块启动一个shell编写的脚本,该脚本主要功能式加载java的classpath并在后台运行这个java程序。
该脚本在linux shell中可以正常启动和停止,但是使用ansible shell模块却每次都启动后进程都消失了,日志没有任何异常,pid文件也生成了。
后来经过一个同事的猜想,是否有程序将该进程kill掉了。

于是产生了以下几种猜想:
1.ansible shell模块执行完shell脚本,就立即关闭当前的shell,进程也就被关闭了。
ansible fork出来子线程来运行脚本,ansible正常退出时会结束所有fork的子线程因为程序启动后被关闭.

尝试解决: 给shell命令开头加个nohup, 结尾加个&, 如果环境变量找不到,加入source ~/.bash_profile
例如:source ~/.bash_profile;nohup /apps/xxx/ss/start.sh &

Linux set命令参数及用法详解 ( https://www.cnblogs.com/liduanjun/p/3536996.html)
shell执行startup.sh无法启动tmocat的问题 ( https://segmentfault.com/q/1010000010375831 )
ansible启动tomcat失败 ( https://www.zhihu.com/question/52712638 )
ansible在远程机器将程序起在后台 ( https://blog.csdn.net/cikenerd/article/details/54411633 )
Ansible常用模块:cron、synchronize、shell、service ( https://blog.csdn.net/lcl_xiaowugui/article/details/81905324 )
关于ansible远程执行的环境变量问题(login shell & nonlogin shelll)( https://blog.csdn.net/u010871982/article/details/78525367 )

如果您喜欢我,可以通过微信请我喝果汁。 如果有疑问,可以留言或者发邮件给我 lhh_nj@163.com