【问题标题】:Foreman rvm upstart not work工头 rvm 新贵不起作用
【发布时间】:2014-06-12 00:24:33
【问题描述】:

Unicorn 不是由 upstart 脚本运行的。

rvm 1.25.23 红宝石 2.1.1 Rails 4.1

config/deploy.rb

  desc 'Foreman init'
  task :foreman_init do
    on roles(:all) do
      foreman_temp = "/home/deployer/tmp/foreman"
      execute  "mkdir -p #{foreman_temp}"
      execute "ln -s #{release_path} #{current_path}"
      within current_path do
        execute "cd #{current_path}"
        execute :bundle, "exec foreman export upstart #{foreman_temp} -a #{application} -u deployer -l /home/deployer/apps/#{application}/log -d #{current_path}"
      end
      sudo "mv #{foreman_temp}/* /etc/init/"
      sudo "rm -r #{foreman_temp}"
    end
  end

/etc/init/depl-web-1.conf

start on starting depl-web
stop on stopping depl-web
respawn

env PORT=5000

setuid deployer

chdir /home/deployer/apps/depl/current

exec bundle exec unicorn_rails -c /home/deployer/apps/depl/current/config/unicorn.rb -E production

/log/upstart/depl-web-1.log 和 production.log 清除

如果您转到应用程序的目录并手动运行命令

bundle exec unicorn_rails -c /home/deployer/apps/depl/current/config/unicorn.rb -E production

独角兽成功上线。

如果在 /etc/init/depl-web-1.conf exec 行添加端口

exec bundle exec unicorn_rails -p $PORT -c

/home/deployer/apps/depl/current/config/unicorn.rb -E production

错误:

/bin/sh: 1: exec: bundle: not found

我使用 rvm

which bundle
/home/deployer/.rvm/gems/ruby-2.1.1/bin/bundle
which rvm
/home/deployer/.rvm/bin/rvm

【问题讨论】:

    标签: ruby-on-rails rvm bundle upstart foreman


    【解决方案1】:

    我最终做了类似于 Denis 的事情,除了每个 RVM 文档使用 Ruby 包装器。这真的很烦人,但根据top -cshift-M 它正在工作。写半详细,因为我希望这对其他人有帮助。

    我的设置是:Digital Ocean、Ubuntu 14.10、Rails 4.0.x、Ruby 2.0.x、RVM 1.26.10。我的 Procfile 仅用于后台作业,因为我使用的是 Passenger 5+Nginx。部署用户是“rails”。我有一个名为“ruby-2.0.0-p598@rockin”的 gemset 用于我的应用程序“rockin”,因为我在盒子上运行了多个应用程序。

    将绝对 PATH 添加到捆绑包对我不起作用。

    这就是我所做的:

    1. 根据docs 创建 rvm 包装器。 (用户是 rails

      rvm alias create rockin ruby-2.0.0-p598@rockin
      
    2. 为 RAILS_ENV 创建 .env 文件,为 bundle 创建 PATH

      RAILS_ENV=production 
      
    3. 尝试将工头出口到暴发户

      rvmsudo foreman export upstart /etc/init -a rockin -u rails
      
    4. 由于在另一个窗口中作为完整性检查的捆绑包问题,决定尾随日志。 (用户是 root

      tail -f /var/log/upstart/rockin-worker-1.log
      
    5. 手动更改新贵文件。我需要编辑的文件是rockin-worker-1.conf。由于大部分东西的格式都很好,并且有我需要的东西,所以我使用上面创建的包装器将 exec 行更改为真正指向 bundle。

      start on starting rockin-worker
      stop on stopping rockin-worker
      respawn
      
      env PORT=5000
      env RAILS_ENV='production'
      
      setuid rails
      
      chdir /home/rails/rockin
      
      exec /usr/local/rvm/wrappers/rockin/bundle exec rake environment resque:work QUEUE=*
      
    6. 运行它!

      sudo start rockin-worker 
      
    7. 您可以查看有尾日志,但如果您没有看到任何输出,那么您就可以开始了!然后通过执行top -cshift-M 仔细检查顶部。我的 resque 工作人员启动并进入等待模式。完美。

    这应该适用于任何使用 rvm 和其他后台工作者(如 sidekiq)的人。

    对于任何说 PATH 会起作用的人,我从我的应用程序的根目录尝试了 which bundlewhereis bundle,并将这些路径用于 .env 文件。两者都不起作用,并且都导致日志抱怨/bin/sh: 1: exec: bundle: not found

    【讨论】:

      【解决方案2】:

      我手动编辑。

      start on starting depl-web
      stop on stopping depl-web
      respawn
      
      env PORT=5000
      env RVM_SHELL=/home/deployer/.rvm/bin/rvm-shell
      env RUBY_VERSION="2.1.5"
      setuid deployer
      script
      chdir /home/deployer/apps/depl/current
      $RVM_SHELL $RUBY_VERSION -c 'bundle exec unicorn_rails -c /home/deployer/apps/depl/current/config/unicorn.rb -E production'
      end script
      

      【讨论】:

        【解决方案3】:

        Foreman 更改了导出时使用的新贵模板文件。

        更改的原因是使用新贵的原生功能清理文件,并通过不暴露 ps 上的环境变量来更安全。

        GitHub 上的相关拉取请求:#438

        GitHub 上的相关问题:#443

        有几种方法可以处理更改,但似乎在.env 文件中将bundle 的路径添加到PATH 应该可以工作。

        【讨论】:

          【解决方案4】:

          我将此添加到我的部署脚本中,它似乎正在工作。我不知道这是否是一个好的解决方案,但它很快。

          execute 'cat /etc/environment > /var/www/my-app/continuous-integration/current/.env'
          

          【讨论】:

            【解决方案5】:

            这可以在不手动编辑新贵文件的情况下工作......

            我让 bundler 安装 binstubs,然后像这样设置我的 Procfile:

            workers: /bin/bash -l -c "./bin/bundle exec sidekiq"
            

            无需手动编辑即可工作。

            【讨论】:

              【解决方案6】:

              对我有用的几乎就像@Denis 给出的解决方案。几乎没有什么不同的是使用 rvm bin 而不是 rvm-shell 和 ruby​​ 版本以及 gems 而不是仅 ruby​​ 版本。所以我最终的 cons 文件是这样的:

              start on starting depl-web
              stop on stopping depl-web
              respawn
              
              env PORT=5000
              env RVM_SHELL=/usr/local/rvm/bin/rvm
              env RUBY_VERSION="ruby_version@gemset_name"
              setuid deploy
              script
              chdir /var/www/depl/current
              $RVM_SHELL $RUBY_VERSION do bundle exec puma -C /var/www/depl/current/config/puma.rb
              end script
              

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2016-10-28
                • 2013-11-30
                • 1970-01-01
                • 2014-03-30
                • 1970-01-01
                • 2013-01-27
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多