Any easy way to start multiple instances at once?

23 views
Skip to first unread message

Greg Campbell

unread,
Feb 5, 2010, 5:19:34 PM2/5/10
to Daemon Kit
Hi all,

Is there any command-line or config-file option to have a daemon-kit
daemon start/stop multiple instances of itself? My current plan is to
just call "bin/my-daemon start --pidfile instance1" and "bin/my-daemon
start --pidfile instance2", but it could be a little cleaner if there
were some way to configure that on a per-environment basis.

Thoughts?
--Greg

Kenneth Kalmer

unread,
Feb 6, 2010, 2:48:32 AM2/6/10
to daemo...@googlegroups.com
Hi Greg

At the moment there is not way to do this. I've wondered about this myself, it should not be too difficult to achieve this. My first theory is that we can use an optional '--instances' argument to achieve this:

$ ./bin/my-daemon start --instances N --pidfile instance.pid

During the daemonizing step we "should" be able to fork the daemonized code twice, giving us N instances. Pid filenames will then be updated to have the instance number just before .pid (ie instance.1.pid).

Greg, do you (or anyone else) want to help test the theory, and possibly another branch ?

Thinks to look at include:

* Detection of multiple instances (for stop)
* Update of generated monitoring files for multiple instances
* Possibility of having this specified in config/environment.rb or specific env file.
* Possibilities to start/restart only a single instance (monitoring configs)

Best

--
Kenneth Kalmer
kenneth...@gmail.com
http://opensourcery.co.za
@kennethkalmer

Josh Owens

unread,
Feb 6, 2010, 9:57:35 AM2/6/10
to daemo...@googlegroups.com
Hey guys,

I have something similar to what you are asking, just using a simple ruby executable that shells out to call the actual launch script for my daemon.  In my case, my daemon is called tweethopper, and I have a bin/cluster.rb and a bin/tweethopper.rb.  Here is what is in cluster.rb and config/cluster.yml:

cluster.rb

#!/usr/bin/env ruby
require 'yaml'
require File.dirname(__FILE__) + '/../config/environment'
cluster = YAML::load(File.open("#{DAEMON_ROOT}/config/cluster.yml")) 

command = ARGV.shift.to_s.to_sym
0.upto(cluster["cluster_size"].to_i - 1) do |server|
  `#{DAEMON_ROOT}/bin/tweethopper #{command} --config daemon_name="tweethopper #{server}" --pid /tmp/tweethopper.#{server}.pid`
end


cluster.yml

cluster_size: 2


Basically, this loops up to your cluster size and starts each daemon with a pid file and a proper daemon name.  Then I can use ./bin/cluster.rb start or ./bin/cluster.rb stop and it does what it should.

--
You received this message because you are subscribed to the Google Groups "Daemon Kit" group.
To post to this group, send email to daemo...@googlegroups.com.
To unsubscribe from this group, send email to daemon-kit+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/daemon-kit?hl=en.

Reply all
Reply to author
Forward
0 new messages