2012-03-05 59 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

相关问题