Detecting unicorn / defining after_fork after master startup
somers.ben at gmail.com
Thu Jul 19 22:55:54 UTC 2012
> 1. What is the best way to determine whether the app is indeed running
> inside a unicorn server?
I actually wound up just setting an environment variable for this. I
manage unicorn through an init.d, and just export UNICORN=true before
it starts up the server. We have the exact scenario you describe,
Unicorn in production and Passenger on our dev machines.
> 2. Is there an established way for adding an after_fork hook after
> Unicorn has already started up?
I just recently had to solve this problem for my team. In my case,
I've got multiple applications getting their unicorn configs managed
through chef, and so didn't want to fill the chef with app-specific
switches. Since the unicorn config file is just ruby code, I just have
my config files check the app directory for a unicorn directory
containing before_fork.rb and after_fork.rb files and load the files
if they exist. It doesn't register the hooks after Unicorn starts, but
it does let you define them outside of the config file.
More information about the mongrel-unicorn