2012-06-14 27 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

相关问题