DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Mickael has posted 15 posts at DZone. View Full User Profile

Daemonize A Ruby Process

  • submit to reddit
        // description of your code here
from :
Here's a neat thing I found. I needed a small bit of Ruby code to run continuously in the background, but because of how Capistrano can't seem to work well with "nohup" and "&" (background job), my ruby script itself needed to be able to fork and detach from the terminal. Here's how you do it: 

pid = fork do
  Signal.trap('HUP', 'IGNORE') # Don't die upon logout

  loop do

    // Some code

    sleep 60