unicorn Ruby/Rack server user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: Amir Yalon <amiryal@yxejamir.net>
Cc: Christos Trochalakis <yatiohi@ideopolis.gr>, unicorn-public@bogomips.org
Subject: [PATCH] doc: reference --keep-file-descriptors for "bundle exec"
Date: Thu, 17 Mar 2016 00:27:36 +0000	[thread overview]
Message-ID: <20160317002736.GA26688@dcvr.yhbt.net> (raw)
In-Reply-To: <1457824748.3666627.547425122.2A828B07@webmail.messagingengine.com>

Amir Yalon <amiryal@yxejamir.net> wrote:
> It became obvious that RVM is not to blame, and the real culprit was
> Bundler’s `bundle exec` script.  From here it was just a matter of
> figuring out how to launch the unicorn script from within the bundle
> using the correct ruby without calling `bundle exec`.  There are a
> number of ways to do that, here is what worked for me:

Ahah, seems like an old problem with bundler defaults.

> ExecStart = /usr/local/rvm/gems/ruby-2.0.0-p645/wrappers/ruby -r
> bundler/setup vendor/bundle/ruby/2.0.0/bin/unicorn -c
> config/unicorn/unicorn.rb -E staging -s myapp@%i

Actually, "bundle exec --keep-file-descriptors" should work
nowadays.  See patch below.

> Thanks again to all participants, your input was invaluable.

No problem.

> P.S.  Notice how I abuse the -s no-op parameter to identify which
> template instance is running in systemd (in the output of ps, for
> example), maybe worth documenting it as a feature?

*shrug* I prefer to use full the full path to the config file
which would already include the app name in it:

	unicorn -c /path/to/my_app/unicorn.conf.rb ...

Subject: [PATCH] doc: reference --keep-file-descriptors for "bundle exec"

"bundle exec" alone is not suitable for use with systemd-style
socket activation due to Ruby 2.0+ behavior of setting close-on-exec
for file descriptors above 2.  However, the "--keep-file-descriptors"
option was added to bundler 1.4.0 to workaround this Ruby 2.0 change
and may be used to prevent Ruby 2.0+ from closing file descriptors
on exec.

Thanks to Amir Yalon and Christos Trochalakis for bringing up
this issue on the mailing list:

 Sandbox                   | 6 +++---
 examples/unicorn@.service | 2 ++
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/Sandbox b/Sandbox
index 997b92f..0760065 100644
--- a/Sandbox
+++ b/Sandbox
@@ -63,9 +63,9 @@ before_exec hook as illustrated by https://gist.github.com/534668
 === Ruby 2.0.0 close-on-exec and SIGUSR2 incompatibility
 Ruby 2.0.0 enforces FD_CLOEXEC on file descriptors by default.  unicorn
-has been prepared for this behavior since unicorn 4.1.0, but we forgot
-to remind the Bundler developers.  This issue is being tracked here:
+has been prepared for this behavior since unicorn 4.1.0, and bundler
+needs the "--keep-file-descriptors" option for "bundle exec":
 == Isolate
diff --git a/examples/unicorn@.service b/examples/unicorn@.service
index b058da5..5b16b5b 100644
--- a/examples/unicorn@.service
+++ b/examples/unicorn@.service
@@ -11,6 +11,8 @@ Wants = unicorn.socket
 After = unicorn.socket
+# bundler users must use the "--keep-file-descriptors" switch, here:
+# ExecStart = bundle exec --keep-file-descriptors /usr/bin/unicorn ...
 ExecStart = /usr/bin/unicorn -c /path/to/unicorn.conf.rb /path/to/config.ru
 Sockets = unicorn.socket
 KillSignal = SIGQUIT

  reply	other threads:[~2016-03-17  0:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-07 23:08 Systemd socket inheritance fails with “not a socket file descriptor” Amir Yalon
2016-03-08  3:31 ` Eric Wong
2016-03-08  7:45   ` Amir Yalon
2016-03-08 17:39     ` Eric Wong
2016-03-08 20:32       ` Amir Yalon
2016-03-09  3:51         ` Eric Wong
2016-03-09 13:19           ` Systemd socket inheritance fails with “not a socket file descriptor” [take2] Christos Trochalakis
2016-03-09 14:06           ` Systemd socket inheritance fails with “not a socket file descriptor” Christos Trochalakis
2016-03-10  9:48             ` Amir Yalon
2016-03-12  5:30               ` Eric Wong
2016-03-12 23:19             ` Amir Yalon
2016-03-17  0:27               ` Eric Wong [this message]
2016-03-17 13:09                 ` [PATCH] doc: reference --keep-file-descriptors for "bundle exec" Amir Yalon
2016-03-17 16:37                   ` 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:

  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=20160317002736.GA26688@dcvr.yhbt.net \
    --to=e@80x24.org \
    --cc=amiryal@yxejamir.net \
    --cc=unicorn-public@bogomips.org \
    --cc=yatiohi@ideopolis.gr \


* 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


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).