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.
828f1d90727a1f3972e0fe55a66be56f?d=identicon&s=25 Tom Harris (tharrisx)
on 2006-01-14 16: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 Harris
Cisco Systems
8217faf2bfdfa7daf10135d41ddd421e?d=identicon&s=25 Jeff Cohen (jeff)
on 2006-01-14 17:37
Tom Harris wrote:
> Is there any way to request WEBrick to shutdown besides hitting CTRL-C
> at the console?

What OS are you running on?
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-01-14 17:41
(Received via mailing list)
killall

On 1/14/06, Tom Harris <tom@tharrisx.homedns.org> 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}'`
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-01-14 17:41
(Received via mailing list)
On 1/14/06, Joe Van Dyk <joevandyk@gmail.com> wrote:
> killall
whoops, ignore that first line.

> On 1/14/06, Tom Harris <tom@tharrisx.homedns.org> 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?
828f1d90727a1f3972e0fe55a66be56f?d=identicon&s=25 Tom Harris (tharrisx)
on 2006-01-14 18:04
Joe Van Dyk wrote:
> On 1/14/06, Joe Van Dyk <joevandyk@gmail.com> wrote:
>> killall
> whoops, ignore that first line.
>
>> On 1/14/06, Tom Harris <tom@tharrisx.homedns.org> 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
Ce60c4f78a63b0695e4dafc4bd7964f7?d=identicon&s=25 Lou Vanek (Guest)
on 2006-01-14 18:08
(Received via mailing list)
on windows, you can do,

 > taskkill /F /IM ruby.exe

taskkill can be run remotely, too.
8217faf2bfdfa7daf10135d41ddd421e?d=identicon&s=25 Jeff Cohen (jeff)
on 2006-01-14 18:33
Lou Vanek 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
828f1d90727a1f3972e0fe55a66be56f?d=identicon&s=25 Tom Harris (tharrisx)
on 2006-01-15 01: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
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-01-15 02:07
(Received via mailing list)
On 1/14/06, Tom Harris <tom@tharrisx.homedns.org> 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?
Ff9e18f0699bf079f1fc91c8d4506438?d=identicon&s=25 James Britt (Guest)
on 2006-01-15 02:58
(Received via mailing list)
Tom Harris 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 Britt

--

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
828f1d90727a1f3972e0fe55a66be56f?d=identicon&s=25 Tom Harris (tharrisx)
on 2006-01-15 03:04
James Britt 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
Ff9e18f0699bf079f1fc91c8d4506438?d=identicon&s=25 James Britt (Guest)
on 2006-01-15 06:02
(Received via mailing list)
Tom Harris 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
828f1d90727a1f3972e0fe55a66be56f?d=identicon&s=25 Tom Harris (tharrisx)
on 2006-01-15 22:59
James Britt wrote:
> Tom Harris 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
Eeba234182bcbd7faed9ff52e233394d?d=identicon&s=25 Douglas Livingstone (Guest)
on 2006-01-16 01:39
(Received via mailing list)
2006/1/15, Tom Harris <tom@tharrisx.homedns.org>:
>
> 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
Ff9e18f0699bf079f1fc91c8d4506438?d=identicon&s=25 James Britt (Guest)
on 2006-01-16 03:36
(Received via mailing list)
Tom Harris 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 Britt

--
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
828f1d90727a1f3972e0fe55a66be56f?d=identicon&s=25 Tom Harris (tharrisx)
on 2006-01-16 17:31
Douglas Livingstone wrote:
> 2006/1/15, Tom Harris <tom@tharrisx.homedns.org>:
>>
>> 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
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-01-16 17:58
(Received via mailing list)
On 1/16/06, Tom Harris <tom@tharrisx.homedns.org> 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.
828f1d90727a1f3972e0fe55a66be56f?d=identicon&s=25 Tom Harris (tharrisx)
on 2006-01-16 20: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
38a8230ed3d5c685558b4f0aad3fc74b?d=identicon&s=25 Joe Van Dyk (Guest)
on 2006-01-17 01:27
(Received via mailing list)
On 1/16/06, Tom Harris <tom@tharrisx.homedns.org> 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.
D10ca8d11301c2f4993ac2279ce4b930?d=identicon&s=25 Adam (Guest)
on 2006-01-17 06:52
Joe Van Dyk wrote:
> On 1/16/06, Tom Harris <tom@tharrisx.homedns.org> 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.