[英]Start Unicorn with Runit and User's RVM
我正在与Chef一起部署Rails App服务器。 刚从Ruby的源安装中切换到RVM(因为我的部署用户遇到了问题)。
现在,我的部署已排序,资产已编译,捆绑器已安装所有宝石。
我的问题是用Runit监督Unicorn。
RVM并非以root用户身份安装-仅当我的部署用户拥有RVM时,如下所示:
$ rvm list
rvm rubies
=* ruby-2.0.0-p247 [ x86_64 ]
我可以从部署用户成功手动启动Unicorn。 但是,它不会作为runit的一部分启动。
我的运行文件如下所示。 我也尝试过这个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
如果我手动运行它,则会出现此错误:
/usr/bin/env: ruby_noexec_wrapper: No such file or directory
我创建了一个小脚本( 要点在这里 ),它确实以root身份运行。 但是,如果我从runit调用它,我会看到工作程序已启动,但是有两个runit进程,但无法停止或重新启动服务:
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
我应该在这里做什么? 移回monit哪个效果很好?
您的运行文件做错了,正在使用二进制文件而不设置环境,为此,您应该使用包装器:
rvm wrapper ruby-2.0.0-p247 --no-links unicorn
为了简化脚本,请使用别名,因此在您决定使用哪个红宝石时,无需更改别名:
rvm alias create my_app_unicorn ruby-2.0.0-p247
并将脚本更改为:
#!/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
这将确保适当的环境用于执行unicorn
并且每当您想要更改运行的红宝石时,只需将别名创建为新的红宝石即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.