简体   繁体   English

使用Runit和用户的RVM启动Unicorn

[英]Start Unicorn with Runit and User's RVM

I'm deploying my Rails App servers with Chef. 我正在与Chef一起部署Rails App服务器。 Have just swapped to RVM from a source install of Ruby (because I was having issues with my deploy user). 刚从Ruby的源安装中切换到RVM(因为我的部署用户遇到了问题)。

Now I have my deploy sorted, assets compiled and bundler's installed all my gems. 现在,我的部署已排序,资产已编译,捆绑器已安装所有宝石。

The problem I have is supervising Unicorn with Runit.. 我的问题是用Runit监督Unicorn。

RVM is not installed as root user - only as my deploy user has it, as follows: RVM并非以root用户身份安装-仅当我的部署用户拥有RVM时,如下所示:

$ rvm list
rvm rubies    
=* ruby-2.0.0-p247 [ x86_64 ]

I can manually start Unicorn successfully from my deploy user. 我可以从部署用户成功手动启动Unicorn。 However, it won't start as part of runit. 但是,它不会作为runit的一部分启动。

My run file looks like this. 我的运行文件如下所示。 I have also tried the solution in this SO question unsuccessfully.. 我也尝试过这个SO问题的解决方案。

#!/bin/bash
cd /var/www/html/deploy/production/current
exec 2>&1
exec chpst -u deploy:deploy /home/deploy/.rvm/gems/ruby-2.0.0-p247/bin/unicorn -E production -c config/unicorn_production.rb

If I run it manually, I get this error: 如果我手动运行它,则会出现此错误:

/usr/bin/env: ruby_noexec_wrapper: No such file or directory

I created a small script ( gist here ) which does run as root. 我创建了一个小脚本( 要点在这里 ),它确实以root身份运行。 However, if I call this from runit, I see the workers start but I get two processes for runit and I can't stop or restart the service: 但是,如果我从runit调用它,我会看到工作程序已启动,但是有两个runit进程,但无法停止或重新启动服务:

Output of ps: ps的输出:

1001     29062     1  0 00:08 ?        00:00:00 unicorn master -D -E production -c /var/www/html/deploy/production/current/config/unicorn_production.rb                                                                                                                    
1001     29065 29062  9 00:08 ?        00:00:12 unicorn worker[0] -D -E production -c /var/www/html/deploy/production/current/config/unicorn_production.rb                                                                                                                 
root     29076   920  0 00:08 ?        00:00:00 su - deploy -c cd /var/www/html/deploy/production/current; export GEM_HOME=/home/deploy/.rvm/gems/ruby-2.0.0-p247; /home/deploy/.rvm/gems/ruby-2.0.0-p247/bin/unicorn -D -E production -c /var/www/html/deploy/production/current/config/unicorn_production.rb
1001     29083 29076  0 00:08 ?        00:00:00 -su -c cd /var/www/html/deploy/production/current; export GEM_HOME=/home/deploy/.rvm/gems/ruby-2.0.0-p247; /home/deploy/.rvm/gems/ruby-2.0.0-p247/bin/unicorn -D -E production -c /var/www/html/deploy/production/current/config/unicorn_production.rb

What should I do here? 我应该在这里做什么? Move back to monit which worked nicely? 移回monit哪个效果很好?

your run file is doing it wrong, you are using the binary without setting the environment, for that purpose you should use wrappers: 您的运行文件做错了,正在使用二进制文件而不设置环境,为此,您应该使用包装器:

rvm wrapper ruby-2.0.0-p247 --no-links unicorn

To simplify the script use alias so it does not need to be changed when you decide which ruby should be used: 为了简化脚本,请使用别名,因此在您决定使用哪个红宝石时,无需更改别名:

rvm alias create my_app_unicorn ruby-2.0.0-p247

And change the script to: 并将脚本更改为:

#!/bin/bash
cd /var/www/html/deploy/production/current
exec 2>&1
exec chpst -u deploy:deploy /home/deploy/.rvm/wrappers/my_app_unicorn/unicorn -E production -c config/unicorn_production.rb

This will ensure proper environment is used for execution of unicorn and any time you want change ruby used to run it just crate alias to a new ruby. 这将确保适当的环境用于执行unicorn并且每当您想要更改运行的红宝石时,只需将别名创建为新的红宝石即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM