# What's the cleanest way to add have a start / stop control with EventMachine

**URL:** <https://www.ruby-forum.com/t/whats-the-cleanest-way-to-add-have-a-start-stop-control-with-eventmachine/153151>\
**Category:** Rails\
**Created:** [November 12, 2008, 6:25pm UTC](https://www.ruby-forum.com/t/whats-the-cleanest-way-to-add-have-a-start-stop-control-with-eventmachine/153151 "2008-11-12T18:25:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rob](https://www.ruby-forum.com/u/rob)\
**Post date:** [November 12, 2008, 6:25pm UTC](https://www.ruby-forum.com/t/whats-the-cleanest-way-to-add-have-a-start-stop-control-with-eventmachine/153151/1 "2008-11-12T18:25:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/838e76/32.png) [@rob](https://www.ruby-forum.com/u/rob)\
**Post date:** [November 13, 2008, 3:08pm UTC](https://www.ruby-forum.com/t/whats-the-cleanest-way-to-add-have-a-start-stop-control-with-eventmachine/153151/2 "2008-11-13T15:08:24Z")

</div>

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)
