我希望有一个进程,如果它崩溃将重新启动。我google了一下,发现一个简单的解决方案是使用daemontools。
我不明白如何配置它。
您似乎正在寻找已在Ubuntu中使用 Upstart 提供的功能。配置中的respawn
节将完全按照您的需要进行操作。我建议不要使用不太标准的方法处理这个问题。
如果没有关于您尝试使用它的流程的更多详细信息,很难说配置应该是什么样子。这取决于它是否分叉并将其置于背景中。 respawn
节的Upstart文档应该为您提供更多信息
不幸的是,还不能正确运行用户工作:无法获得新贵运行用户工作
让我们假设我们想让计算器应用程序保持运行,即使它被火烧死(信号9)。
在/etc/init/calculator.conf
中创建一个配置文件(基于这篇文章):
#!upstart
description "Calculator"
# Start job via the daemon control script. Replace "gert" with your username.
exec su -l gert -c 'export DISPLAY=:0; /usr/bin/gnome-calculator'
# Restart the process if it dies with a signal
# or exit code not given by the 'normal exit' stanza.
respawn
# Give up if restart occurs 10 times in 90 seconds.
respawn limit 10 90
通过运行
启动它#!upstart
description "Calculator"
# Start job via the daemon control script. Replace "gert" with your username.
exec su -l gert -c 'export DISPLAY=:0; /usr/bin/gnome-calculator'
# Restart the process if it dies with a signal
# or exit code not given by the 'normal exit' stanza.
respawn
# Give up if restart occurs 10 times in 90 seconds.
respawn limit 10 90
它会在您当前的显示屏上打开(:0
),并在关闭它后重新启动,享受真棒。
识别进程ID,例如通过ps aux | grep calculator
:
sudo start calculator
用火把它杀死。
gert 13695 0.2 0.4 349744 16460 ? Sl 13:38 0:00 /usr/bin/gnome-calculator
观看它再次出现:
sudo kill -9 13695
请注意,对于具有适当用户工作支持的Ubuntu 13.04计划的计划,这将更加优雅。