<p>如果你在Ubuntu上,我建议你去看看<a href="http://upstart.ubuntu.com/" rel="nofollow">upstart</a>。这比<code>inittab</code>好得多,但说实话,它确实涉及一些学习曲线。</p>
<p><strong>编辑</strong>(作者:布莱尔):这是我最近为自己的一个程序编写的新贵脚本的改编示例。像这样的一个基本的新贵脚本是相当可读/可理解的,尽管(像许多这样的东西一样)当你开始做一些花哨的事情时,它们会变得复杂起来。</p>
<pre><code>description "mydaemon - my cool daemon"
# Start and stop conditions. Runlevels 2-5 are the
# multi-user (i.e, networked) levels. This means
# start the daemon when the system is booted into
# one of these runlevels and stop when it is moved
# out of them (e.g., when shut down).
start on runlevel [2345]
stop on runlevel [!2345]
# Allow the service to respawn automatically, but if
# crashes happen too often (10 times in 5 seconds)
# theres a real problem and we should stop trying.
respawn
respawn limit 10 5
# The program is going to daemonise (double-fork), and
# upstart needs to know this so it can track the change
# in PID.
expect daemon
# Set the mode the process should create files in.
umask 022
# Make sure the log folder exists.
pre-start script
mkdir -p -m0755 /var/log/mydaemon
end script
# Command to run it.
exec /usr/bin/python /path/to/mydaemon.py logfile /var/log/mydaemon/mydaemon.log
</code></pre>