Reputation: 3909
I have a rails (3.2) application that is deployed on OSX (Lion). Ultimately, I would like unicorn to startup automatically when and if the machine is restarted.
This answer has gotten me pretty far, but I still can't seem to get it to work.
I use capistrano2 to deploy the application with capistrano-unicorn to help start and stop the process. I am also managing ruby with rvm on the server.
When I issue a cap unicorn:start
command from my development machine, capistrano-unicorn will send the command RAILS_ENV=production BUNDLE_GEMFILE=/path/to/gemfile bundle exec unicorn -c /path/to/unicorn.rb -E production -D
, and thus, I'd like the plist file to replicate this command on startup.
Here is my plist file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/rails_applications/deployments/meat/shared/bundle/ruby/1.9.1/bin:/Users/mlp/.rvm/gems/ruby-1.9.3-p194/bin:/Users/mlp/.rvm/gems/ruby-1.9.3-p194@global/bin:/Users/mlp/.rvm/rubies/ruby-1.9.3-p194/bin:/Users/mlp/.rvm/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin</string>
<key>RAILS_ENV</key>
<string>production</string>
<key>BUNDLE_GEMFILE</key>
<string>/rails_applications/deployments/meat/current/Gemfile</string>
<key>GEM_HOME</key>
<string>/rails_applications/deployments/meat/shared/bundle/ruby/1.9.1</string>
<key>GEM_PATH</key>
<string>/rails_applications/deployments/meat/shared/bundle/ruby/1.9.1</string>
</dict>
<key>Disabled</key>
<false/>
<key>Label</key>
<string>local.unicorn</string>
<key>ProgramArguments</key>
<array>
<string>/Users/mlp/.rvm/gems/ruby-1.9.3-p194@global/bin/bundle</string>
<string>exec</string>
<string>/rails_applications/deployments/meat/shared/bundle/ruby/1.9.1/bin/unicorn</string>
<string>-c</string>
<string>/rails_applications/deployments/meat/current/config/unicorn.rb</string>
<string>-E</string>
<string>production</string>
</array>
<key>KeepAlive</key>
<true/>
<key>RunAtLoad</key>
<true/>
<key>EnableTransactions</key>
<false/>
<key>StandardOutPath</key>
<string>/tmp/unicorn.out</string>
<key>StandardErrorPath</key>
<string>/tmp/unicorn.err</string>
<key>Debug</key>
<true/>
</dict>
</plist>
Here is my unicorn config file:
app_path = "/rails_applications/deployments/meat/current"
working_directory app_path
pid "#{app_path}/tmp/pids/unicorn.pid"
stderr_path "#{app_path}/log/unicorn.stderr.log"
stdout_path "#{app_path}/log/unicorn.stdout.log"
listen "/tmp/unicorn.meat.sock"
worker_processes 2
#long timeouts for big file processing
timeout 360
You'll notice I don't include the -D
argument in the plist file, as it is recommended that launchctl daemons don't launch their own. I also include explicit paths to GEM_HOME, GEM_PATH, and PATH, as I figure these won't be set before login (for the rvm stuff).
When I kill unicorn that was started via capistrano and try to load my plist file (sudo launchctl load /Library/LaunchDaemons/local.unicorn.plist
) I see the following in my error log file:
/Users/mlp/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find bundler (>= 0) amongst [actionmailer-3.2.14, actionmailer-3.2.12, actionpack-3.2.14, actionpack-3.2.12, activemodel-3.2.14, activemodel-3.2.12, activerecord-3.2.14, activerecord-3.2.12, activeresource-3.2.14, activeresource-3.2.12, activesupport-3.2.14, activesupport-3.2.12, arel-3.0.3, arel-3.0.2, bcrypt-ruby-3.0.1, bootstrap-sass-2.3.0.0, bootstrap-will_paginate-0.0.6, builder-3.0.4, cancan-1.6.9, capistrano-2.15.4, capistrano-2.13.5, capistrano-unicorn-0.2.0, carrierwave-0.10.0, carrierwave-0.9.0, carrierwave-0.8.0, carrierwave-meta-0.0.5, carrierwave_backgrounder-0.2.2, carrierwave_backgrounder-0.2.1, carrierwave_backgrounder-0.2.0, celluloid-0.15.2, celluloid-0.14.0, chart-js-rails-0.0.6, coffee-rails-3.2.2, coffee-script-2.2.0, coffee-script-source-1.4.0, connection_pool-1.2.0, connection_pool-1.0.0, devise-2.2.3, erubis-2.7.0, exception_notification-4.0.1, excon-0.32.1, excon-0.13.4, execjs-1.4.0, faker-1.0.1, ffi-1.9.3, fog-1.21.0, fog-1.3.1, fog-brightbox-0.0.1, fog-core-1.21.1, fog-json-1.0.0, formatador-0.2.4, geoutm-1.0.2, geoutm-1.0.1, gmaps4rails-2.0.5, gmaps4rails-1.5.6, gon-5.0.4, highline-1.6.19, highline-1.6.15, hike-1.2.3, hike-1.2.1, hooks-0.4.0, hooks-0.3.4, hooks-0.3.3, i18n-0.6.9, i18n-0.6.5, i18n-0.6.4, journey-1.0.4, jquery-rails-2.1.4, json-1.8.1, json-1.8.0, json-1.7.7, kgio-2.9.2, mail-2.5.4, mail-2.4.4, mime-types-1.25.1, mime-types-1.25, mini_exiftool-2.4.1, mini_exiftool-1.6.0, multi-select-rails-0.9.5, multi_json-1.9.2, multi_json-1.8.4, multi_json-1.8.2, multi_json-1.8.1, multi_json-1.7.7, multi_json-1.7.3, naturally-1.1.0, net-scp-1.1.2, net-scp-1.0.4, net-sftp-2.1.2, net-sftp-2.0.5, net-ssh-2.8.0, net-ssh-2.6.7, net-ssh-2.6.2, net-ssh-gateway-1.2.0, net-ssh-gateway-1.1.0, nokogiri-1.5.11, nokogiri-1.5.6, orm_adapter-0.4.0, pg-0.17.1, pg-0.14.1, pg_search-0.7.3, pg_search-0.7.2, pg_search-0.7.0, polyamorous-0.6.4, polyamorous-0.6.3, polyamorous-0.5.0, polyglot-0.3.4, polyglot-0.3.3, rack-1.4.5, rack-cache-1.2, rack-mini-profiler-0.1.31, rack-mini-profiler-0.1.23, rack-pjax-0.7.0, rack-protection-1.3.2, rack-ssl-1.3.4, rack-ssl-1.3.3, rack-test-0.6.2, rails-3.2.14, rails-3.2.12, railties-3.2.14, railties-3.2.12, raindrops-0.13.0, rake-10.2.2, rake-10.1.0, rake-10.0.3, rbind-0.0.24, rdoc-3.12.2, redis-3.0.6, redis-3.0.4, redis-namespace-1.4.1, redis-namespace-1.3.0, rmagick-2.13.2, ropencv-0.0.15, ropencv-0.0.14, ruby-hmac-0.4.0, ruby-vips-0.3.6, ruby-vips-0.3.5, rvm-capistrano-1.3.0, sass-3.2.3, sass-rails-3.2.4, sidekiq-2.17.1, sidekiq-2.11.2, simple_form-2.0.4, sinatra-1.3.5, slim-1.3.6, sprockets-2.2.2, squeel-1.1.1, squeel-1.1.0, squeel-1.0.18, temple-0.5.5, thor-0.19.1, thor-0.18.1, thor-0.17.0, tilt-1.3.7, tilt-1.3.4, timers-1.1.0, treetop-1.4.15, treetop-1.4.12, tzinfo-0.3.39, tzinfo-0.3.37, tzinfo-0.3.35, uber-0.0.4, uber-0.0.2, uglifier-1.3.0, uglifier-1.2.3, unicorn-4.8.2, uuidtools-2.1.4, uuidtools-2.1.3, warden-1.2.1, wicked-1.0.2, will_paginate-3.0.3] (Gem::LoadError)
from /Users/mlp/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
from /Users/mlp/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems.rb:1231:in `gem'
from /Users/mlp/.rvm/gems/ruby-1.9.3-p194@global/bin/bundle:18:in `<main>'
from /Users/mlp/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `eval'
from /Users/mlp/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'
Since bundle install
uses the deployment
option, all my gems are install under the deployment folder /rails_applications/deployments/meat/shared/bundle
, so it seems the environment is not getting set up correctly. From what I understand, by setting BUNDLE_GEMFILE with bundle exec
, this should be taken care of, but obviously this isn't working.
Any help getting this working would be greatly appreciated.
Upvotes: 1
Views: 654
Reputation: 8106
Looks like the bundler
gem is not installed in the ruby-1.9.3-p194@global
gemset. How about:
rvm ruby-1.9.3-p194@global && gem install bundler
If that doesn't work, try adding this to your Gemfile and then doing bundle install
again:
gem 'bundler'
Upvotes: 1