簡體   English   中英

使用Runit和用戶的RVM啟動Unicorn

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM