在Ansible中守护可执行文件 [英] Daemonizing an executable in ansible
问题描述
我试图在ansible中创建一个任务,该任务执行shell命令以使用&在守护程序模式下运行可执行文件.类似于
I am trying to create a task in ansible which executes a shell command to run an executable in daemon mode using &. Something like following
-name: Start daemon
shell: myexeprogram arg1 arg2 &
看到的是我是否保留&该任务将立即返回,并且该过程不会开始.如果我删除& ansible任务等待相当长的时间却没有返回.
What am seeing is if I keep & the task returns immediately and the process is not started . If I remove & ansible task waits for quite some time without returning.
通过ansible正确建议在守护程序模式下启动程序的方法.请注意,我不想将此作为服务运行,而是基于某些条件的临时后台进程.
Appreciate suggestion on proper way to start program in daemon mode through ansible. Pls note that I dont want to run this as a service but an adhoc background process based on certain conditions.
推荐答案
使用&"运行程序不会使程序成为守护程序,它仅在后台运行.要创建真正的守护程序",您的程序应执行
Running program with '&' does not make program a daemon, it just runs in background. To make a "true daemon" your program should do steps described here.
如果您的程序是用C编写的,则可以调用daemon()函数,该函数将为您完成.然后,即使没有'&',您也可以启动程序最后,它将作为守护程序运行.
If your program is written in C, you can call daemon() function, which will do it for you. Then you can start your program even without '&' at the end and it will be running as a daemon.
另一种选择是使用 daemon 来调用程序,这也可以完成这项工作.
The other option is to call your program using daemon, which should do the job as well.
- name: Start daemon
shell: daemon -- myexeprogram arg1 arg2
这篇关于在Ansible中守护可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!