From: Eric Wong <normalperson@yhbt.net>
To: unicorn list <mongrel-unicorn@rubyforge.org>
Subject: Re: Detecting unicorn / defining after_fork after master startup
Date: Thu, 19 Jul 2012 16:13:34 -0700 [thread overview]
Message-ID: <20120719231334.GA19342@dcvr.yhbt.net> (raw)
In-Reply-To: <CAJf_-Utd8NE4rL68mj-8=4q+O+9NrMF8j7e213N13Xcw718A=Q@mail.gmail.com>
Matt Sanders <matt@modal.org> wrote:
> 1. What is the best way to determine whether the app is indeed running
> inside a unicorn server?
Unicorn.listener_names will return a non-empty array of listener
addresses.
> 2. Is there an established way for adding an after_fork hook after
> Unicorn has already started up?
Nothing that I know of.
> I'm aware of the ability to do this via the config file but I don't
> want my users to have to add something to their unicorn config file.
> Is there an equivalent to passenger's
> PhusionPassenger.on_event(:starting_worker_process) method?
Lately, I've been favoring the following pattern instead:
def initialize
@init_pid = $$
...
end
def initialize_child_fork
@init_pid = $$
...
end
def call(env)
initialize_child_fork if @init_pid != $$
...
end
The overhead is negligible and works regardless of server (even in
non-HTTP servers somebody may write). I really don't like code
that would need to special case for all sorts of servers:
foo_for_passenger if defined?(PhusionPassenger)
foo_for_unicorn if defined?(Unicorn)
foo_for_something_fastcgi if defined?(SomethingFastCGI)
foo_for_something_scgi if defined?(SomethingSCGI)
foo_for_something_else_that_forks if defined?(YetAnotherForkingRackServer)
foo_for_something_else if defined?(SomethingElse)
...
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying
next prev parent reply other threads:[~2012-07-19 23:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-19 22:43 Detecting unicorn / defining after_fork after master startup Matt Sanders
2012-07-19 22:55 ` Ben Somers
2012-07-19 22:59 ` Matt Sanders
2012-07-19 23:13 ` Eric Wong [this message]
2012-07-21 19:42 ` Matt Sanders
2012-07-22 21:20 ` Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/unicorn/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120719231334.GA19342@dcvr.yhbt.net \
--to=normalperson@yhbt.net \
--cc=mongrel-unicorn@rubyforge.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/unicorn.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).