Forum: Ruby on Rails What's the cleanest way to add have a start / stop control with EventMachine

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
05d8aae3736c731bcfc2c2a5c2a5f316?d=identicon&s=25 Rob Lacey (braindeaf)
on 2008-11-12 18:25
(Received via mailing list)
Hi there,

I'm new to playing with EventMachine and I wondered if anyone has a nice
way of backgrounding it and start / stopping it from the command line
like an init script.

e.g. ./mydaemon start|stop

I've not seen an example of this and search through the Juggernaut gem
source I couldn't get the come I'd stolen from it to work with a basic
echo server.

e.g. mydaemon start|stop

Any ideas?

RobL
292e825e3d670ee973e512801e5071a4?d=identicon&s=25 joserwan (Guest)
on 2008-11-13 15:08
(Received via mailing list)
Here's what I did :

# =============================
# script/em_manager
# I did a chmod +x on this file

#!/usr/bin/env ruby
require 'rubygems'
require 'daemons'
  options = {
    :app_name   => "em_manager",
    #:ARGV       => ['start', '-f', '--', 'param_for_myscript']
    #:dir_mode   => :normal,
    #:dir        => path,
    :multiple   => false,
    #:ontop      => true,
    :mode       => :load,
    :log_output => true,
    #:keep_pid_files => true,
    #:backtrace  => true,
   # :monitor    => true
  }

#=====================
# app/daemons/em_client.rb

EventMachine::run {
   (...)
  }


Daemons.run('./app/daemons/em_client.rb', options)
This topic is locked and can not be replied to.