From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS33070 50.56.128.0/17 X-Spam-Status: No, score=-0.2 required=5.0 tests=AWL shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: archivist@yhbt.net Delivered-To: archivist@dcvr.yhbt.net Received: from rubyforge.org (50-56-192-79.static.cloud-ips.com [50.56.192.79]) by dcvr.yhbt.net (Postfix) with ESMTP id E5D8F1F4CA for ; Thu, 19 Jul 2012 23:13:38 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 7DB272E069; Thu, 19 Jul 2012 23:13:38 +0000 (UTC) X-Original-To: mongrel-unicorn@rubyforge.org Delivered-To: mongrel-unicorn@rubyforge.org Received: from dcvr.yhbt.net (dcvr.yhbt.net [64.71.152.64]) by rubyforge.org (Postfix) with ESMTP id 96CCD2E05E for ; Thu, 19 Jul 2012 23:13:35 +0000 (UTC) Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id B679C1F449; Thu, 19 Jul 2012 23:13:34 +0000 (UTC) Date: Thu, 19 Jul 2012 16:13:34 -0700 From: Eric Wong To: unicorn list Subject: Re: Detecting unicorn / defining after_fork after master startup Message-ID: <20120719231334.GA19342@dcvr.yhbt.net> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: mongrel-unicorn@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: mongrel-unicorn-bounces@rubyforge.org Errors-To: mongrel-unicorn-bounces@rubyforge.org Matt Sanders 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