attempt to rename PID file when possible
[unicorn.git] / Sandbox
blob3c7f2263c1027304dc5dcc443f082762f9e07c65
1 = Tips for using \Unicorn with Sandbox installation tools
3 Since unicorn includes executables and is usually used to start a Ruby
4 process, there are certain caveats to using it with tools that sandbox
5 RubyGems installations such as
6 {Bundler}[http://gembundler.com/] or
7 {Isolate}[http://github.com/jbarnette/isolate].
9 == General deployment
11 If you're sandboxing your unicorn installation and using Capistrano (or
12 similar), it's required that you sandbox your RubyGems in a per-application
13 shared directory that can be used between different revisions.
15 unicorn will stash its original command-line at startup for the USR2
16 upgrades, and cleaning up old revisions will cause revision-specific
17 installations of unicorn to go missing and upgrades to fail.   If you
18 find yourself in this situation and can't afford downtime, you can
19 override the existing unicorn executable path in the config file like
20 this:
22         Unicorn::HttpServer::START_CTX[0] = "/some/path/to/bin/unicorn"
24 Then use HUP to reload, and then continue with the USR2+QUIT upgrade
25 sequence.
27 Environment variable pollution when exec-ing a new process (with USR2)
28 is the primary issue with sandboxing tools such as Bundler and Isolate.
30 == Bundler
32 === Running
34 If you're bundling unicorn, use "bundle exec unicorn" (or "bundle exec
35 unicorn_rails") to start unicorn with the correct environment variables
37 ref: http://mid.gmane.org/9ECF07C4-5216-47BE-961D-AFC0F0C82060@internetfamo.us
39 Otherwise (if you choose to not sandbox your unicorn installation), we
40 expect the tips for Isolate (below) apply, too.
42 === RUBYOPT pollution from SIGUSR2 upgrades
44 This is no longer be an issue as of bundler 0.9.17
46 ref: http://mid.gmane.org/8FC34B23-5994-41CC-B5AF-7198EF06909E@tramchase.com
48 === BUNDLE_GEMFILE for Capistrano users
50 You may need to set or reset the BUNDLE_GEMFILE environment variable in
51 the before_exec hook:
53         before_exec do |server|
54           ENV["BUNDLE_GEMFILE"] = "/path/to/app/current/Gemfile"
55         end
57 === Other ENV pollution issues
59 If you're using an older Bundler version (0.9.x), you may need to set or
60 reset GEM_HOME, GEM_PATH and PATH environment variables in the
61 before_exec hook as illustrated by http://gist.github.com/534668
63 === Ruby 2.0.0 close-on-exec and SIGUSR2 incompatibility
65 Ruby 2.0.0 enforces FD_CLOEXEC on file descriptors by default.  unicorn
66 has been prepared for this behavior since unicorn 4.1.0, but we forgot
67 to remind the Bundler developers.  This issue is being tracked here:
68 https://github.com/bundler/bundler/issues/2628
70 == Isolate
72 === Running
74 Installing "unicorn" as a system-wide Rubygem and using the
75 isolate gem may cause issues if you're using any of the bundled
76 application-level libraries in unicorn/app/* (for compatibility
77 with CGI-based applications, Rails <= 2.2.2, or ExecCgi).
78 For now workarounds include doing one of the following:
80 1. Isolating unicorn, setting GEM_HOME to your Isolate path,
81    and running the isolated version of unicorn.  You *must* set
82    GEM_HOME before running your isolated unicorn install in this way.
84 2.  Installing the same version of unicorn as a system-wide Rubygem
85     *and* isolating unicorn as well.
87 3. Explicitly setting RUBYLIB or $LOAD_PATH to include any gem path
88    where the unicorn gem is installed
89    (e.g. /usr/lib/ruby/gems/1.9.1/gems/unicorn-VERSION/lib)
91 === RUBYOPT pollution from SIGUSR2 upgrades
93 If you are using Isolate, using Isolate 2.x is strongly recommended as
94 environment modifications are idempotent.
96 If you are stuck with 1.x versions of Isolate, it is recommended that
97 you disable it with the <tt>before_exec</tt> hook prevent the PATH and
98 RUBYOPT environment variable modifications from propagating between
99 upgrades in your Unicorn config file:
101         before_exec do |server|
102           Isolate.disable
103         end