Forum: Ruby on Rails Stopping WEBrick?

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.
Tom H. (Guest)
on 2006-01-14 17:28
Is there any way to request WEBrick to shutdown besides hitting CTRL-C
at the console?

I'm looking for, perhaps, a script/shutdown command, or perhaps a
special URL that will request WEBrick to die.

It can be a command run in a different shell, or, as I said, a special
URL.

Anyone?

Tom H.
Cisco Systems
Jeff C. (Guest)
on 2006-01-14 18:37
Tom H. wrote:
> Is there any way to request WEBrick to shutdown besides hitting CTRL-C
> at the console?

What OS are you running on?
Joe Van D. (Guest)
on 2006-01-14 18:41
(Received via mailing list)
killall

On 1/14/06, Tom H. <removed_email_address@domain.invalid> wrote:
> Is there any way to request WEBrick to shutdown besides hitting CTRL-C
> at the console?

kill -9 `ps aux | grep 'script/server' | awk '{print $2}'`
Joe Van D. (Guest)
on 2006-01-14 18:41
(Received via mailing list)
On 1/14/06, Joe Van D. <removed_email_address@domain.invalid> wrote:
> killall
whoops, ignore that first line.

> On 1/14/06, Tom H. <removed_email_address@domain.invalid> wrote:
> > Is there any way to request WEBrick to shutdown besides hitting CTRL-C
> > at the console?
>
> kill -9 `ps aux | grep 'script/server' | awk '{print $2}'`

Or were you looking for something else?
Tom H. (Guest)
on 2006-01-14 19:04
Joe Van D. wrote:
> On 1/14/06, Joe Van D. <removed_email_address@domain.invalid> wrote:
>> killall
> whoops, ignore that first line.
>
>> On 1/14/06, Tom H. <removed_email_address@domain.invalid> wrote:
>> > Is there any way to request WEBrick to shutdown besides hitting CTRL-C
>> > at the console?
>>
>> kill -9 `ps aux | grep 'script/server' | awk '{print $2}'`
>
> Or were you looking for something else?

I'm on Windows.

Tom
Lou V. (Guest)
on 2006-01-14 19:08
(Received via mailing list)
on windows, you can do,

 > taskkill /F /IM ruby.exe

taskkill can be run remotely, too.
Jeff C. (Guest)
on 2006-01-14 19:33
Lou V. wrote:
> on windows, you can do,
>
>  > taskkill /F /IM ruby.exe
>
> taskkill can be run remotely, too.

Just beware I think that will kill any other ruby processes also running
too.

If you need to shutdown the exact ruby instance that is running Webrick,
you can get the process id from the webbrick console output (it's right
before the port number).

for example, if 1648 is the pid displayed in the webrick shell:

taskkill /F /PID 1648

will kill just webbrick without touching any other ruby processes.

Jeff
www.softiesonrails.com
Tom H. (Guest)
on 2006-01-15 02:59
>>  > taskkill /F /IM ruby.exe
>>
>> taskkill can be run remotely, too.
> taskkill /F /PID 1648

But, there's now way to cleanly request WEBrick to shutdown?

I am starting WEBrick from an Ant script, and I'd like to have a
shutdown target in there as well, to match all my other processes. The
Ant script cannot read the pid from some other console window. And I
don't want to kill the process, I want to request the web server to
shutdown cleanly. I cannot do this? Sounds like something to be added.

Tom
Joe Van D. (Guest)
on 2006-01-15 03:07
(Received via mailing list)
On 1/14/06, Tom H. <removed_email_address@domain.invalid> wrote:
> Ant script cannot read the pid from some other console window. And I
> don't want to kill the process, I want to request the web server to
> shutdown cleanly. I cannot do this? Sounds like something to be added.

When ant starts a process, it can't get the pid of the started process?
James B. (Guest)
on 2006-01-15 03:58
(Received via mailing list)
Tom H. wrote:
> Is there any way to request WEBrick to shutdown besides hitting CTRL-C
> at the console?
>
> I'm looking for, perhaps, a script/shutdown command, or perhaps a
> special URL that will request WEBrick to die.
>
> It can be a command run in a different shell, or, as I said, a special
> URL.
>
> Anyone?

Common problem, so I have wrote a script that autogenerates basic
WEBrick server code, and always include a magic URL to shutdown the
server.


  s = HTTPServer.new( :Port => some_port_var

  # ... app-specific stuff

  s.mount_proc('/quit') { |req, resp| s.shutdown;  exit;  }


Season to taste.


James B.

--

http://www.ruby-doc.org       - Ruby Help & Documentation
http://www.artima.com/rubycs/ - The Journal By & For Rubyists
http://www.rubystuff.com      - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com     - Playing with Better Toys
http://www.30secondrule.com   - Building Better Tools
Tom H. (Guest)
on 2006-01-15 04:04
James B. wrote:
> Common problem, so I have wrote a script that autogenerates basic
> WEBrick server code, and always include a magic URL to shutdown the
> server.
>
>
>   s = HTTPServer.new( :Port => some_port_var
>
>   # ... app-specific stuff
>
>   s.mount_proc('/quit') { |req, resp| s.shutdown;  exit;  }
>
>
> Season to taste.

Where do I put this, in my routes.rb? Doesn't look like this would work.

WEBrick is not part of my project, and I'd really like to require users
to use the one-click installer, install gem, and rails themselves. I
don't think I want to have to support a custom version of WEBrick as
well as my own code, and what happens when a new version of Rails comes
out?

Tom
James B. (Guest)
on 2006-01-15 07:02
(Received via mailing list)
Tom H. wrote:
>>
>>  s.mount_proc('/quit') { |req, resp| s.shutdown;  exit;  }
>>
>>
>>Season to taste.
>
>
> Where do I put this, in my routes.rb? Doesn't look like this would work.

It goes into the code that actually creates and runs the instance of a
WEBrick server:  webrick_server.rb

The code simply associates a URL with a proc.


James
Tom H. (Guest)
on 2006-01-15 23:59
James B. wrote:
> Tom H. wrote:
>>>
>>>  s.mount_proc('/quit') { |req, resp| s.shutdown;  exit;  }
>>>
>>>
>>>Season to taste.
>>
>>
>> Where do I put this, in my routes.rb? Doesn't look like this would work.
>
> It goes into the code that actually creates and runs the instance of a
> WEBrick server:  webrick_server.rb
>
> The code simply associates a URL with a proc.
>
>
> James

This is a change to the existing code. I guess I'm asking for either of
the following:

1. Is there an existing way to do this that already in the code?
2. Can someone who has committer-rights add something like this to the
WEBrick code?

As I said, I don't want to have to support my own version of WEBrick. I
just need to be able to shutdown the specific WEBrick my Ant script
started, either locally or remotely, in a platform-agnostic way.

For something like Rails to be taken seriously in business situations,
it has to be more managable, and that being able to remotely control the
service on any platform. Relying on *nix commands is fine for hackers,
but unfortunately, most businesses still run only Windows. At my
company, we've been pushing for our product to be supported on Solaris
or Linux for quite some time, but the response is always that the change
is not cost-effective, since very few customers are actually interested
in running our products on anything but Windows. They have the knowledge
in-house to deal with it, they are comfortable. Anyway, </rant>

Tom
Douglas L. (Guest)
on 2006-01-16 02:39
(Received via mailing list)
2006/1/15, Tom H. <removed_email_address@domain.invalid>:
>
> As I said, I don't want to have to support my own version of WEBrick. I
> just need to be able to shutdown the specific WEBrick my Ant script
> started, either locally or remotely, in a platform-agnostic way.
>

As James says, if you have an instance of HTTPServer, you can shut it
down with s.shutdown.

> This is a change to the existing code.

Yes, but it is a change to existing Rails code, rather than a change
to existing WEBrick code, so you won't have to support your own
version of WEBrick.

Douglas
James B. (Guest)
on 2006-01-16 04:36
(Received via mailing list)
Tom H. wrote:
>
I find Rails far more manageable than the various J2EE apps I've worked
with precisely because I *can* go and easily mod *any* code I please.
It's Ruby, not Java byte-code.  I'm not at the mercy of some
one-size-fits-all config or management tool that addresses every
possible option expect those I actually care about.

Installing a custom webrick_server.rb file is not a complicated task,
and gives you complete, portable control.


James B.

--
http://www.ruby-doc.org       - Ruby Help & Documentation
http://www.artima.com/rubycs/ - The Journal By & For Rubyists
http://www.rubystuff.com      - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com     - Playing with Better Toys
http://www.30secondrule.com   - Building Better Tools
Tom H. (Guest)
on 2006-01-16 18:31
Douglas L. wrote:
> 2006/1/15, Tom H. <removed_email_address@domain.invalid>:
>>
>> As I said, I don't want to have to support my own version of WEBrick. I
>> just need to be able to shutdown the specific WEBrick my Ant script
>> started, either locally or remotely, in a platform-agnostic way.
>>
>
> As James says, if you have an instance of HTTPServer, you can shut it
> down with s.shutdown.
>
>> This is a change to the existing code.
>
> Yes, but it is a change to existing Rails code, rather than a change
> to existing WEBrick code, so you won't have to support your own
> version of WEBrick.
>
> Douglas

So, I made a copy of the webrick_server.rb file in the following folder
in my app:

lib\ruby\gems\1.8\gems\rails-1.0.0\lib

I added the statement inbetween, as such:

    server = WEBrick::HTTPServer.new(params)
    server.mount_proc('/quit') { |req, resp| server.shutdown;  exit;  }
    server.mount('/', DispatchServlet, options)

I then run WEBrick, and try to browse to the /quit URL and get:

Routing Error

Recognition failed for "/quit"

It looks like my overriding copy of the webrick_server.rb file isn't
being used. I don't want to have to include all of rails in my app. I
would rather require that users of this download ruby and install rails
themselves.

What am I doing wrong here? And how do others package and deploy things
like this?

Tom
Joe Van D. (Guest)
on 2006-01-16 18:58
(Received via mailing list)
On 1/16/06, Tom H. <removed_email_address@domain.invalid> wrote:
> >
>
> Routing Error
>
> Recognition failed for "/quit"
>
> It looks like my overriding copy of the webrick_server.rb file isn't
> being used. I don't want to have to include all of rails in my app. I
> would rather require that users of this download ruby and install rails
> themselves.

Just curious, why don't you want to include Rails in the vendor
directory of your application?  That way, you can be sure that the
version of Rails that the customer is using is the one that's sure to
work with your application.
Tom H. (Guest)
on 2006-01-16 21:30
> Just curious, why don't you want to include Rails in the vendor
> directory of your application?  That way, you can be sure that the
> version of Rails that the customer is using is the one that's sure to
> work with your application.

This is an open-source project, for which I'm developing a rails web
config. I don't want to include ruby and rails in the project, because I
want the user to install ruby on their own, if they want to use the web
config. And, when rails gets fixes, I want the user to be responsible
for getting the update, not me.

So, any idea how to get my copy of this file to be used, short of being
forced include the entirity of rails into my project?

Tom
Joe Van D. (Guest)
on 2006-01-17 02:27
(Received via mailing list)
On 1/16/06, Tom H. <removed_email_address@domain.invalid> wrote:
> > Just curious, why don't you want to include Rails in the vendor
> > directory of your application?  That way, you can be sure that the
> > version of Rails that the customer is using is the one that's sure to
> > work with your application.
>
> This is an open-source project, for which I'm developing a rails web
> config. I don't want to include ruby and rails in the project, because I
> want the user to install ruby on their own, if they want to use the web
> config. And, when rails gets fixes, I want the user to be responsible
> for getting the update, not me.

What if Rails gets fixes that break your application?  Or a user
downloads Rails 1.1 (or Rails 0.13.4)?

> So, any idea how to get my copy of this file to be used, short of being
> forced include the entirity of rails into my project?

I don't know off-hand, but I'm sure the solution won't be too difficult.
Adam (Guest)
on 2006-01-17 07:52
Joe Van D. wrote:
> On 1/16/06, Tom H. <removed_email_address@domain.invalid> wrote:
>> > Just curious, why don't you want to include Rails in the vendor
>> > directory of your application?  That way, you can be sure that the
>> > version of Rails that the customer is using is the one that's sure to
>> > work with your application.
>>
>> This is an open-source project, for which I'm developing a rails web
>> config. I don't want to include ruby and rails in the project, because I
>> want the user to install ruby on their own, if they want to use the web
>> config. And, when rails gets fixes, I want the user to be responsible
>> for getting the update, not me.
>
> What if Rails gets fixes that break your application?  Or a user
> downloads Rails 1.1 (or Rails 0.13.4)?
>
>> So, any idea how to get my copy of this file to be used, short of being
>> forced include the entirity of rails into my project?
>
> I don't know off-hand, but I'm sure the solution won't be too difficult.

I put in a ticket for script/server stop and script/server restart to be
added.
This topic is locked and can not be replied to.