Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash脚本中另一个用户下的Ruby RVM_Ruby_Bash_Rvm_Sudo_Su - Fatal编程技术网

Bash脚本中另一个用户下的Ruby RVM

Bash脚本中另一个用户下的Ruby RVM,ruby,bash,rvm,sudo,su,Ruby,Bash,Rvm,Sudo,Su,通过su命令和其他脚本在其他用户下启动ruby脚本的最佳方式是什么 我有一个bash脚本,其中包含用于启动unicorn的以下命令: sudo -u unicornuser sh -l -c "bundle exec unicorn_rails -E production -D" 此脚本是一个init.d脚本,它在系统启动时执行,也可以手动执行 问题是默认的Rubyon系统是1.8,其他rubyes(1.9)在RVM下工作。我需要修改上面的脚本,使其能够使用RVM(非系统范

通过su命令和其他脚本在其他用户下启动ruby脚本的最佳方式是什么

我有一个bash脚本,其中包含用于启动unicorn的以下命令:

sudo -u unicornuser sh -l -c "bundle exec unicorn_rails -E production -D"
此脚本是一个init.d脚本,它在系统启动时执行,也可以手动执行

问题是默认的Rubyon系统是1.8,其他rubyes(1.9)在RVM下工作。我需要修改上面的脚本,使其能够使用RVM(非系统范围)执行ruby

现在,我迁移了这个符号:

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

这对我来说很有效,但我想一定有更好的方法可以做到这一点。

你应该使用包装器:

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/rvm
替换为
echo$rvm_path