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.0 required=5.0 tests=none 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 AF6D71F433 for ; Sat, 21 Jul 2012 19:43:08 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id B2FEF2E05F; Sat, 21 Jul 2012 19:43:06 +0000 (UTC) X-Original-To: mongrel-unicorn@rubyforge.org Delivered-To: mongrel-unicorn@rubyforge.org Received: from mail-ob0-f178.google.com (mail-ob0-f178.google.com [209.85.214.178]) by rubyforge.org (Postfix) with ESMTP id BB3E52E05D for ; Sat, 21 Jul 2012 19:42:57 +0000 (UTC) Received: by obbwd20 with SMTP id wd20so8722565obb.23 for ; Sat, 21 Jul 2012 12:42:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=Lrlhh/peov5DCtLnI8+VvenYFGay/HhajHYlsa8xIfg=; b=h/bM2jX9h2ICWq4WWvzVsTEibLKP6ABIGEQk2VSB1qTDNMhgj6LLvqQCU+L4+2sXMq lkbKoOF53x7a3lSN8B1syq/zIMzLk+1I8RAq9ehRLwtqwvH2iLTurXN2ANEE6SJ2AD4k Ager87U2H1SLf+Ao5BP9xTGahw736AJZKcfPkuEkONglAM7oeFpXkxaIGTwzifFO3Pv/ ZPgx121bOcfCrQqathrc8ZYFAZJKuRzjkdUTCn+ZvW3rbp//0NibCh3wjBmk978mocUf N/2U0gz4WjTAkf5l+/jYIHxloOPSTjhcGeemzc5hR5WQXMg4J32kC3i+g55fJqE1+S+r j5kQ== MIME-Version: 1.0 Received: by 10.182.89.102 with SMTP id bn6mr13323395obb.7.1342899777069; Sat, 21 Jul 2012 12:42:57 -0700 (PDT) Received: by 10.60.46.133 with HTTP; Sat, 21 Jul 2012 12:42:57 -0700 (PDT) In-Reply-To: <20120719231334.GA19342@dcvr.yhbt.net> References: <20120719231334.GA19342@dcvr.yhbt.net> Date: Sat, 21 Jul 2012 14:42:57 -0500 Message-ID: Subject: Re: Detecting unicorn / defining after_fork after master startup From: Matt Sanders To: unicorn list X-Gm-Message-State: ALoCoQmSJVqXdPeqYe8O+f16FhC9Bxa2ZQ2qsDMSpoauS9hXk3h7/ct7LAo567mz0XrkoqbDNdmv 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 Eric, Thanks! I definitely agree in general with that pattern. In this case I'd ideally like some activity on the forked child before the next request cycle - that is, if the forked child doesn't serve any requests for a little bit, I'd still like my behavior to be initialized. Do you know of a way to get this behavior without a direct after fork hook? Thanks for your help! -Matt On Thu, Jul 19, 2012 at 6:13 PM, Eric Wong wrote: > 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 _______________________________________________ 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