title: Configure unicorn service script using RVM
body: <p>In my <code>/etc/init.d/unicorn</code> startup script I have the hard-coded paths as follows:</p>
  
  <pre><code>export GEM_HOME=/usr/local/rvm/gems/ruby-2.2.0-dev
  export GEM_PATH=/usr/local/rvm/gems/ruby-2.2.0-dev:/usr/local/rvm/gems/ruby-2.2.0-dev/gems:/usr/local/rvm/gems/ruby-2.2.0-dev@global/gems
  
  DAEMON=/usr/local/rvm/gems/ruby-2.2.0-dev/bin/unicorn
  
  UNICORN_OPTS="-D -c /home/unicorn/unicorn.conf -E production"
  </code></pre>
  
  <p>I am using RVM and when I change the ruby version, then the current ruby should be used for unicorn.</p>
  
  <h2>Question 1</h2>
  
  <p>So how can I make sure that these variables always point to the proper ruby?</p>
  
  <h2>Question 2</h2>
  
  <p>In my bundle I am using rack 1.5.5. Now on my production server I had to install the <code>unicorn</code> gem as a "stand-alone-gem" so that I can start my server using:</p>
  
  <pre><code>service unicorn start
  </code></pre>
  
  <p>Now the <code>unicorn</code> gem installed <code>rack 1.6.x</code> and now my Rails app crashed because rack is already loaded. Now locally I would just execute it with <code>bundle</code> but how can I do that when I am using this <code>/etc/inid.d</code> script.</p>
  
  <p>The part where the server is started looks like follows, and I don't know how I could "inject" the bundler call there or if that is a good practise at all:</p>
  
  <pre><code># ...
  
  log_daemon_msg "Starting $DESC" $NAME || true
  if start-stop-daemon --start --quiet --oknodo --pidfile $PID --exec $DAEMON -- $UNICORN_OPTS; then
  </code></pre>
  
  <p>The config: <code>/home/unicorn/unicorn.conf</code></p>
  
  <pre><code>listen "127.0.0.1:8080"
  worker_processes 2
  user "rails"
  working_directory "/home/myapp"
  pid "/home/unicorn/pids/unicorn.pid"
  stderr_path "/home/unicorn/log/unicorn.log"
  stdout_path "/home/unicorn/log/unicorn.log"
  </code></pre>