ansible shell 之运行后台程序

最近在使用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)

猜你喜欢

转载自www.cnblogs.com/lihuanhuan/p/11421459.html
今日推荐