How do I setup an init.d rc script for a Daemon-kit project?
I am using the Ruby Daemon-kit to setup a services that does various background operatio开发者_如何学编程ns for my Rails application.
It works fine when I call in on the commandline:
./bin/bgservice
How do I go about creating a daemon initd starter script for it, so that it will autostart on reboot?
There's a few approaches:
You could write
/etc/init.d/
scripts that could be placed into the/etc/rc?.d/
directories (or wherever they live on your target distributions). Some details on this mechanism can be found in the Debian policy guidelines and openSUSE initscript tutorial. There's an annoying number of distribution-specific idiosyncrasies in initscripts, so don't feel about writing a simple one and asking distributions to contribute 'better' ones tailored for their environment. (For example, any Debian-derived distribution will provide the immensely usefulstart-stop-daemon(8)
helper, but it is sorely missing from other distributions.)You could write
upstart
job specifications for the distributions that supportupstart
(which I think is Ubuntu, Google ChromeOS, Fedora, .. more?).upstart
documentation is still pretty weak, but there are some details and plenty of examples in/etc/init/
on Ubuntu, probably the same location in other distributions that useupstart
. Getting the dependencies correct may be some work across all distributions, butupstart
job specifications look far simpler to write and maintain than initscripts.You could add lines to
/etc/inittab
on distributions that still support the standard SysV-initinittab(5)
file. This would only be useful if your program doesn't do the usual daemonfork(2)
/setsid(2)
/fork(2)
incantation, asinit
uses the pid it gets fromfork(2)
to determine if your program needs to be restarted.Modern Vixie
cron(8)
supports a@reboot
specifier incrontab(5)
files. This can be used both by the system crontab as well as user crontabs, which might be nice if you just want to run the program as your usual login account.
As the author of daemon-kit I've avoided making any init-style scripts due to coping with the various distributions and they're migrations from old init-V style to newer upstart/insserv, saving myself a nightmare.
How I recommend to do this is to use the god config-generator, and ensure god is started on boot (by runit or some other means), and god starts the daemon up initially and keeps it running.
At best I'll expand daemon-kit to be able to generate runit scripts for boot...
HTH.
精彩评论