Search code examples
ruby-on-railsexecbundleruby-on-rails-5unicorn

How do I tell Unicorn to run Rails using "bundle exec"?


I'm running Unicorn with Rails 5 on Ubuntu 14.04. I'm running Unicorn as a daemon, using a script, /etc/init.d/unicorn,

case "$1" in
  start)
        check_config
        check_app_root

        log_daemon_msg "Starting $DESC" $NAME || true
        if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON -- $UNICORN_OPTS; then

In a separate file, /etc/default/unicorn, I have the DAEMON and UNICORN_OPTS variable defined ...

UNICORN_OPTS="-D -c $CONFIG_RB -E $RAILS_ENV"
...
DAEMON="$GEM_PATH/bin/unicorn"

My quesiton is, how do I tell Unicorn that when it runs rails to prefix it with "bundle exec"? I need bundle exec because I'm getting all these complaints in my unicorn log complaining about gem versions and how bundle exec will save teh day.


Solution

  • Bundle needs to be run from the directory of the app root.

    Your DAEMON should look something like cd $APP_ROOT && $GEM_PATH/bin/bundle exec unicorn