Command-line ruby: Spawn and control multiple daemons

Posted on 2013-10-19
Medium Priority
Last Modified: 2013-10-21
I'm new to Ruby and could use some advice on what approach I should take. I need a command line script that can spawn two daemons and stop them when asked. Ideally there'd be 3 files in total.


I'd start it from the command line like this:
$ ./loader.rb start

It would spawn a daemon each for server.rb and server_2.rb, and then exit (leaving the daemons running). I could then run 'loader.rb' at any point to shut down the two daemons:

$ ./loader.rb stop

I've been looking at the "Daemons" Gem, which seems like a good approach. I could use some help w/ the syntax though. I think I need to use "Daemons.call", but I'm not clear on how to source in code from other files with it.
Question by:zumpoof
  • 2
LVL 10

Accepted Solution

Andrew Doades earned 2000 total points
ID: 39584644
Used to use this in an old rails app;

require 'rubygems'
require 'daemons'

Daemons.run('wp_cron.rb', :app_name => 'wp_cron', :dir_mode => :script, :log_output => true)

Open in new window

Hope this helps..

Author Closing Comment

ID: 39587067
This is exactly what I'm looking for. Thanks, doades!

Author Comment

ID: 39587077
One more quick question- I have two daemons, but it seems that only the first 'Daemons.run' call gets executed. The second one gets ignored (I checked w/ 'ps -ax'). Is there a way to spawn two daemons instead of just one?

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

The purpose of this article is to demonstrate how we can use conditional statements using Python.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question