Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to determine the status of a puma server #364

Closed
krmichelos opened this issue Sep 5, 2013 · 13 comments
Closed

How to determine the status of a puma server #364

krmichelos opened this issue Sep 5, 2013 · 13 comments

Comments

@krmichelos
Copy link

When using Puma::Server I don't see a way to determine the status (running, stopped, etc.) of the server. Am I missing something or is this not possible. An example of when this would be helpful is to ensure the server is stopped after calling the stop method.

@evanphx
Copy link
Member

evanphx commented Sep 9, 2013

I'll add those APIs. The status is there it's just not nicely exposed.

@krmichelos
Copy link
Author

Great; Thanks

@sethvargo
Copy link

@evanphx is there something quick we can do in the meantime before you have a chance to make those APIs public?

@evanphx
Copy link
Member

evanphx commented Sep 11, 2013

If you must, you could use instance_variable_get to grab the @status ivar. I'd love to get some ideas about what you want to use the status for.

@evanphx
Copy link
Member

evanphx commented Sep 11, 2013

Hm, ok. Looking at status isn't going to tell you much. Mostly that the beginning of #run was executed. What do you really want to know? That Puma is serving requests? What are the cases where it would not start?

@sethvargo
Copy link

@evanphx if you start the server in the background, it may not start immediately and we need to wait until it's ready to proceed.

@krmichelos
Copy link
Author

I think what we are looking for is something to tell us if puma is currently available to server requests or is not. running and backlog can tell us if it is processing requests or has some waiting to process. We need to know if it is in a state where it is able to accept requests. Like when stop is call async how do we tell when the server has stopped and is no longer available to accept requests.

@krisleech
Copy link

Could use use while ! nc -vz localhost 9000; do sleep 1; done to wait for the port to become open, or do you need to know it can actually serve HTTP?

@krmichelos
Copy link
Author

@krisleech
I wouldn't use nc as it not generally going to be available on Windows. I have code like this:

def running?
  begin
    uri = URI(@url)
    if uri.host == '0.0.0.0' then uri.host = '127.0.0.1' end
    Net::HTTP.get_response(uri)
  rescue Errno::ECONNREFUSED
    false
  else
    true
  end
end

But it feels clunky and has more potential for not behaving as intended than just being able to ask the puma server if it is up.

@krisleech
Copy link

@krmichelos Ah, I thought you where talking about having something external to Puma, not built-in.

@evanphx
Copy link
Member

evanphx commented Sep 13, 2013

So I added a nice API for you to use! I haven't added docs for it yet, but you can check it out here: b24920d

You'll want to create your own Events object and pass it into Server.new so that you can register callbacks on it. Your blocks/callbacks will be called from the thread puma is running the server in, so you can use a ConditionVariable to block until the server has fully started.

@evanphx evanphx closed this as completed Sep 13, 2013
@sethvargo
Copy link

❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants