Foreman rvm upstart无法工作

5
Unicorn无法通过upstart脚本运行。
rvm版本为1.25.23,ruby版本为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执行行中添加端口

执行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
6个回答

4

我最终做了和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添加到bundle中对我无效。

以下是我所做的:

  1. Create rvm wrapper per docs. (user is rails)

    rvm alias create rockin ruby-2.0.0-p598@rockin
    
  2. Create .env file for RAILS_ENV and PATH for bundle

    RAILS_ENV=production 
    
  3. Attempt to foreman export to upstart

    rvmsudo foreman export upstart /etc/init -a rockin -u rails
    
  4. Decided to tail the logs because of the bundle issue in another window as sanity check. (user is root)

    tail -f /var/log/upstart/rockin-worker-1.log
    
  5. Change the upstart file manually. The file I needed to edit was rockin-worker-1.conf. Since most of the thing was pretty formatted and had what I needed, I changed the exec lines to truly point to bundle using the wrapper created above.

    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. Run it!

    sudo start rockin-worker 
    
  7. You can check with the tailed logs, but if you see no output, you're good to go! Then double-check top by doing top -c and shift-M. My resque worker started up and went into waiting mode. PERFECT.

这适用于使用rvm和其他后台工作程序(如sidekiq)的任何人。
对于任何说PATH可以起作用的人,我在我的应用程序根目录尝试了 which bundle whereis bundle 两种方式,并将这些路径用于.env文件。两者都不起作用,日志中都会出现“/bin/sh:1:exec:bundle:未找到”的错误提示。

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

1

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

更改的原因是使用upstart本地功能清理文件,并通过不在ps上公开环境变量来增强安全性。

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

Github上相关的问题:#443

有几种处理更改的方法,但似乎将路径添加到.env文件中的PATH应该可以解决问题。


0
我的解决方案与 @Denis 给出的几乎相同。唯一不同的是使用 rvm 而不是 rvm-shell,以及使用 Ruby 版本和 Gem 而非仅使用 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

0

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

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

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

它可以在没有手动编辑的情况下工作。


0

我把这个加到了我的部署脚本里面,看起来效果不错。虽然我不知道它是否是一个好的解决方案,但至少速度很快。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接