2012-06-14 39 views
0

通過su命令和其他腳本在其他用戶下啓動ruby腳本的最佳方式是什麼?來自Bash腳本的另一位用戶下的Ruby RVM

我有用於啓動麒麟以下命令bash腳本:

sudo -u unicornuser sh -l -c "bundle exec unicorn_rails -E production -D" 

這個腳本是一個的init.d腳本,它被執行時,系統啓動和手動也。

問題是系統上默認的紅寶石是1.8,其他rubyes(1.9)在RVM下工作。我需要修改上面的腳本,它可以與RVM

現在我已經遷移爲這個標誌(非系統範圍)執行rubt:

su -l -c "rvm use ruby-1.9.3-p125 && bundle exec unicorn_rails -E production -D" unicornuser 

這個工作對我來說,但我想一定有更好的方法來做到這一點。

回答

1

你應該使用包裝:

rvm wrapper ruby-1.9.3-p125 ext_1.9.3 bundle 

這將創建$rvm_path/bin/ext_1.9.3_bundle,所以現在你可以使用:

/full/path/to/rvm/bin/ext_1.9.3_bundle exec unicorn_rails -E production -D 

與輸出替換/full/path/to/rvmecho $rvm_path

相關問題