在 ansible 中守护可执行文件 [英] Daemonizing an executable in ansible

查看:41
本文介绍了在 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 '&'不会使程序成为守护进程,它只是在后台运行.要制作真正的守护进程",您的程序应该执行 此处.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆