【问题标题】:Unicorn startup on OSX deploymentOSX 部署上的独角兽启动
【发布时间】:2014-04-07 17:47:40
【问题描述】:

我有一个部署在 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 参数,因为建议 launchctl 守护程序不要启动它们自己的。我还包括 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 选项,我所有的gem 都安装在部署文件夹/rails_applications/deployments/meat/shared/bundle 下,因此似乎环境设置不正确。据我了解,通过将 BUNDLE_GEMFILE 设置为bundle exec,应该注意这一点,但显然这不起作用。

我们将不胜感激任何帮助完成这项工作。

【问题讨论】:

  • 真的,即使你怀疑我做的一切都是正确的,我们也会很感激你的提示。
  • 不要这样做,强烈考虑使用 Rails 4.1 附带的github.com/rails/spring,并升级到最新的 Ruby。
  • 这不是用于开发和测试,而是用于生产。该应用程序在实验室环境中通过 Mac 提供。如果有人无意中重新启动了这台机器,我希望它立即启动并运行
  • 你检查过你的.bundle/config文件了吗?

标签: ruby-on-rails macos bundler unicorn


【解决方案1】:

看起来bundler gem 没有安装在ruby-1.9.3-p194@global gemset 中。怎么样:

rvm ruby-1.9.3-p194@global && gem install bundler

如果这不起作用,请尝试将其添加到您的 Gemfile 中,然后再次执行 bundle install

gem 'bundler'

【讨论】:

  • 感谢您的帮助。 Bundler 已安装在此 gemset 下,但我确认我确实重新安装无济于事。
  • 更新的答案表明也可以尝试将 gem 'bundler' 添加到 Gemfile,然后添加 bundle install
  • 我现在无法重新启动这台机器来尝试一下,但会在可以的时候重新启动。您能否详细说明您认为这可能会解决问题的原因。
  • 如果你得到的错误是Could not find bundler (&gt;= 0),那么看起来捆绑器 gem 丢失了。我有一种感觉,当它失败时,它没有使用你认为它应该使用的 gem。
猜你喜欢
  • 1970-01-01
  • 2012-06-01
  • 2023-03-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
相关资源
最近更新 更多