2012-03-05 90 views
1

我想開始一個Ruby腳本unicorn_rails,並在腳本執行許多命令,當腳本獲取到下一行爲什麼試圖啓動unicorn_rails作爲守護進程時停止ruby腳本?

%x[bash -ic "bash <(. ~/.bashrc); cd /home/www-data/rails_app; bundle exec unicorn_rails -p 8000 -E production -c /home/www-data/rails_app/config/unicorn.rb -D"] 

的腳本停止,生成以下輸出

[1]+ Stopped     ./setup_rails.rb 

並返回到Linux提示符。如果我輸入「fg」,腳本結束運行,腳本停止的行被執行,獨角獸開始作爲守護進程。

如果我在單獨的腳本中運行該行,腳本將不停止地完成。

UPDATE_1 -

我的.bashrc源,因爲早期的腳本我安裝了RVM,並把它與正確的環境我有以下的運行:

%x[echo "[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\"" >> .bashrc] 
%x[bash -ic "bash <(. ~/.bashrc); rvm install ruby-1.9.2-p290; rvm 1.9.2-p290 --default;"] 

所以,如果我想運行RVM,紅寶石的正確版本,並捆綁我需要採購的.bashrc

末UPDATE_1

有沒有人有任何想法可能導致一個紅寶石腳本停止,如果控制Z被按下?

回答

1

不知道它爲什麼會停止,但我的一般經驗法則是永遠不會將我的.bashrc發送到腳本中 - 這可能是您的問題的源頭,但我無法確定沒有看到內容它。你應該能夠改變你的腳本,如:

$ vi setup_rails.sh 

#!/usr/bin/bash 

# EDIT from comments below 
# expanding from a one liner to a better script... 

$RVM_PATH=$HOME/.rvm/scripts 

# install 1.9.2-p290 unless it's installed 
$RVM_PATH/rvm info 1.9.2-p290 2&>1 >/dev/null || $RVM_SH install 1.9.2-p290 

# run startup command inside rvm shell 
$RVM_PATH/rvm-shell 1.9.2-p290 -c "cd /home/www-data/rails_app && bundle exec unicorn_rails -p 8000 -E production -c /home/www-data/rails_app/config/unicorn.rb -D" 

這應該會給你相同的結果。

+0

#Josh - 我添加了一個更新1,解釋了爲什麼我採購.bashrc。 – 2012-04-06 01:14:35

+0

我看到... rvm ...我非常避免在生產(或任何環境)中使用rvm。但是,如果這就是你所拍攝的,有幾個選擇。 (似乎進入保存評論,繼續)首先,簽出'rvm-exec',我從來沒有得到它的正常工作,但它的工作有點像'bundle exec' AFAIK。在過去,我有一個簡單的叫做ruby的完整路徑來安裝rvm。醜,但它應該工作。我試圖找到一個例子,但使用它已經有一段時間了,它們似乎已經消失了。 – jmervine 2012-04-06 20:32:05

+0

好吧,從一點搜索,你應該可以簡單地執行'$ HOME/.rvm/scripts/rvm install ruby​​-1.9.2-p290 2>/dev/null; $ HOME/.rvm/bin/rvm-shell ruby​​-1.9.2-p290 -c「cd/home/www-data/rails_app && bundle exec unicorn_rails -p 8000 -E production -c/home/www-data/rails_app /config/unicorn.rb -D 「'這是未經測試的,它或非常接近它*應該*工作。 – jmervine 2012-04-06 20:51:24