# WEBrick::Daemon and WEBrick

**URL:** <https://www.ruby-forum.com/t/webrick-daemon-and-webrick/88353>\
**Category:** Ruby\
**Created:** [March 9, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/webrick-daemon-and-webrick/88353 "2007-03-09T23:08:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [March 9, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/webrick-daemon-and-webrick/88353/1 "2007-03-09T23:08:01Z")

</div>

Is it possible to use the WEBrick::Daemon with WEBrick::AbstractServlet.  
Here is what i’m running for the basic servlet:

dir = Dir::pwd  
server = WEBrick::HTTPServer.new(  
:Port =\> port,  
:DocumentRoot =\> dir  
end

server.mount “/gateway”, RUBYAMF::WEBrickServlet  
trap “INT” do server.shutdown end  
server.start

I’ve seen an example saying you have to subclass the HTTPServer and just  
run the WEBrick::Daemon.start when initializing. But can this be done  
with servlets?

Thanks.

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [March 18, 2007, 2:14am UTC](https://www.ruby-forum.com/t/webrick-daemon-and-webrick/88353/2 "2007-03-18T02:14:26Z")

</div>

On Mar 9, 2007, at 14:08, Aaron S. wrote:

> server.mount “/gateway”, RUBYAMF::WEBrickServlet  
> trap “INT” do server.shutdown end  
> server.start
> 
> I’ve seen an example saying you have to subclass the HTTPServer and  
> just  
> run the WEBrick::Daemon.start when initializing. But can this be done  
> with servlets?

Servlets run in a server, so daemonize after you’ve started the  
HTTPServer and mounted your servlets.

---

<div class="post-metadata">

**Author:** ![ktheory](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/e480ec/32.png) [@ktheory](https://www.ruby-forum.com/u/ktheory)\
**Post date:** [March 18, 2007, 4:47am UTC](https://www.ruby-forum.com/t/webrick-daemon-and-webrick/88353/3 "2007-03-18T04:47:18Z")

</div>

Eric H. wrote:

> On Mar 9, 2007, at 14:08, Aaron S. wrote:
> 
> > server.mount “/gateway”, RUBYAMF::WEBrickServlet  
> > trap “INT” do server.shutdown end  
> > server.start
> > 
> > I’ve seen an example saying you have to subclass the HTTPServer and  
> > just  
> > run the WEBrick::Daemon.start when initializing. But can this be done  
> > with servlets?
> 
> Servlets run in a server, so daemonize after you’ve started the  
> HTTPServer and mounted your servlets.

I figured it out actually:

server = WEBrick::HTTPServer.new(  
:Port =\> OPTIONS[:port],  
:DocumentRoot =\> OPTIONS[:working\_dir],  
:ServerType =\> OPTIONS[:server\_type],  
:BindAddress =\> OPTIONS[:ip]  
)

server type is either WEBrick::Daemon of WEBrick::SimpleServer
