2013-08-29 28 views
0

我正在與Chef部署我的Rails應用服務器。剛從Ruby的源代碼安裝交換到RVM(因爲我的部署用戶遇到問題)。用Runit和用戶的RVM啓動Unicorn

現在我有我的部署排序,資產編譯和打包機的所有我的寶石。

我已經與Runit監督獨角獸的問題..

RVM未安裝爲root用戶 - 僅作爲我的部署用戶,如下所示:

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

我可以手動從我的部署用戶成功啓動Unicorn。但是,它不會作爲runit的一部分啓動。

我的運行文件看起來像這樣。我自己也嘗試在這SO question不成功的解決方案..

#!/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 

如果我手動運行它,我得到這個錯誤:它不以root身份運行

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

我創建了一個小腳本(gist here) 。但是,如果我把這個從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哪個工作很好?

回答

4

您運行文件做錯了,您使用的是二進制沒有設置環境,爲此,你應該使用包裝:

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,並且任何時候您想要更改ruby用於運行它只是將別名打包到新的ruby。

+0

感謝您的回答。我以部署用戶身份運行了包裝器和別名(假設這是因爲root無權訪問rvm)。然而,runit仍然不會啓動它,如果我以root身份手動運行,它會提供:ruby_noexec_wrapper找不到。 – simonmorley

+0

這實際上完成了它。需要幾次殺死守護進程。謝謝,快樂的日子:) – simonmorley