那么,谁应该守护进程? 脚本还是调用者?
我总是想知道应该由谁来做。 在 Ruby 中,我们有 Daemons 库,允许 Ruby 脚本自行守护。 然后,查看God(一个进程监控工具,类似于monit) 页面,我看到上帝可以守护进程。
有没有明确的答案?
I'm always wondering who should do it. In Ruby, we have the Daemons library which allows Ruby scripts to daemonize themselves. And then, looking at God (a process monitoring tool, similar to monit) page, I see that God can daemonize processes.
Any definitive answer out there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能无法得到明确的答案,因为我们通常会得到两者:进程具有守护进程本身的能力,进程监视器具有守护进程其子进程的能力。
就我个人而言,我更喜欢让进程监视器或脚本来执行此操作,原因如下:
1. 如果进程监视器希望密切关注其子进程,以便在它们死掉时重新启动它们,则可以选择不对它们进行守护进程。 当监视器的子进程之一退出时,SIGCHLD 将被传递到监视器。 在嵌入式系统中,我们经常这样做。
2. 通常,在守护进程时,您还可以设置euid 和egid。 我不喜欢将系统级策略的知识(例如要使用的 uid)编码到每个子进程中。
3. 它允许将同一应用程序重新用作命令行工具或守护程序(我坦率地承认这在实践中很少发生)。
You probably cannot get a definitive answer, as we generally end up with both: the process has the ability to daemonize itself, and the process monitor has the ability to daemonize its children.
Personally I prefer to have the process monitor or script do it, for a few reasons:
1. if the process monitor wishes to closely follow its children to restart them if they die, it can choose not to daemonize them. A SIGCHLD will be delivered to the monitor when one of its child processes exits. In embedded systems we do this a lot.
2. Typically when daemonizing, you also set the euid and egid. I prefer not to encode into every child process a knowledge of system-level policy like uids to use.
3. It allows re-use of the same application as either a command line tool or a daemon (I freely admit that this rarely happens in practice).
我想说你的脚本最好这样做。 我不知道那里的进程监控工具,但我认为用户可能会使用替代工具,这意味着让脚本来做这件事会更好。
如果您可以设想脚本以非守护程序方式运行,我会向脚本添加一个选项来启用或禁用守护程序化。
I would say it is better for your script to do it. I don't know your process monitoring tool there, but I would think users could potentially use an alternative tool, which means that having the script do it would be preferable.
If you can envision the script run in non-daemon fashion, I would add an option to the script to enable or disable daemonization.