Ruby Daemons, Services, Processes, and Forks

This page has notes about our research into Ruby programming, specifically how to keep a Ruby program running consistently and ready for incoming requests. == Serv-O-Lux Serv-O-Lux is a collection of Ruby classes that are useful for daemon and process management, and for writing your own Ruby services. The code is well documented and tested. == Ideas from Rubyists Run your script with nohup and there you have your daemon. I also use this kind of skeleton in the "daemon script" itself., "w") { |f| f << $$ }
  def clean_up!
    FileUtils.rm PID_FILE
  Signal.trap 15 { clean_up! }

Making a daemon in MRI

Making a daemon in MRI is straight forward: fork a process and hand off control to the init process. Since JRuby doesn't do forking, I'm curious how people are handling this. The consensus seems to be running some script in the background with "nohup". Example:
  nohup jruby script/daemon < /dev/null > my_log_file.log 2>&1 


GlassFish gem supports daemonizing on linux and solaris platforms. Just run glassfish with -d flag.


Start-Stop Daemon

Start-Stop daemon: A standard Debian distribution contains the useful start-stop-daemon in the directory /sbin. It is used to start program as dameon when this program are not designed (or packaged) in this way.


What's Next?

blog comments powered by Disqus