我有一个部署在OSX(Lion)上的rails(3.2)应用程序。最终,我希望独角兽在机器重新启动时自动启动。
This回答让我走得很远,但我似乎还无法让它发挥作用。
我使用capistrano2部署应用程序capistrano-unicorn来帮助启动和停止该过程。我也在服务器上用rvm管理ruby。
当我从开发机器发出cap unicorn:start
命令时,capistrano-unicorn将发送命令RAILS_ENV=production BUNDLE_GEMFILE=/path/to/gemfile bundle exec unicorn -c /path/to/unicorn.rb -E production -D
,因此,我希望plist文件在启动时复制此命令。
这是我的plist文件:
<?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>
这是我的独角兽配置文件:
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
您会注意到我没有在plist文件中包含-D
参数,因为建议startctl守护程序不要启动它们。我还包括GEM_HOME,GEM_PATH和PATH的显式路径,因为我认为在登录之前不会设置这些路径(对于rvm东西)。
当我杀死通过capistrano启动的独角兽并尝试加载我的plist文件(sudo launchctl load /Library/LaunchDaemons/local.unicorn.plist
)时,我在错误日志文件中看到以下内容:
/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>'
由于bundle install
使用deployment
选项,所有我的宝石都安装在部署文件夹/rails_applications/deployments/meat/shared/bundle
下,因此环境似乎没有正确设置。根据我的理解,通过设置BUNDLE_GEMFILE和bundle exec
,应该注意这一点,但显然这不起作用。
非常感谢任何帮助实现这项工作。
答案 0 :(得分:1)
看起来bundler
gemset中没有安装ruby-1.9.3-p194@global
gem。怎么样:
rvm ruby-1.9.3-p194@global && gem install bundler
如果这不起作用,请尝试将其添加到您的Gemfile中,然后再次执行bundle install
:
gem 'bundler'