使用特定版本的 ruby 在 cron 上运行 gem [英] Running a gem on cron with a specific version of ruby
问题描述
我们需要按 cron 计划运行某个 gem 应用程序,因此我们设置了一个专门的用户来运行此 gem.
We need a certain gem application run on a cron schedule, so we have a dedicated user set up to run this gem.
我们目前使用的是 ruby 1.9.2
We are currently using ruby 1.9.2
[jobrunner@test-load] rvm list
rvm rubies
ruby-1.8.7-p299 [ x86_64 ]
ruby-1.9.2-p180 [ x86_64 ]
=* ruby-1.9.2-p290 [ x86_64 ]
ruby-1.9.3-p125 [ x86_64 ]
ruby-1.9.3-p374 [ x86_64 ]
ruby-1.9.3-p392 [ x86_64 ]
ruby-1.9.3-p448 [ x86_64 ]
ruby-2.0.0-p247 [ x86_64 ]
# => - current
# =* - current && default
# * - default
不幸的是,我需要这个用户在 ruby 1.9.3 上运行.更改默认 ruby 版本不是一个选项,因为 rvm 安装在系统范围内 (/usr/local/rvm/bin/rvm
) 并且系统上的其他用户依赖于 1.9.2.
Unfortunately I need this user to run on ruby 1.9.3. Changing the default ruby version is not an option because rvm is installed system wide (/usr/local/rvm/bin/rvm
) and other users on the system rely on 1.9.2.
如果我在一个交互式会话中,它会很简单
If I were in an interactive session, it would be as simple as
rvm use 1.9.3
但是,我似乎无法在非交互式会话中(即在 crontab 中)使用 rvm use
.(我尝试将其粘贴到我的 bashrc
文件中并告诉 cron 查看我的 bashrc
文件.我最终对自己进行了 forkbombing ..)
However, it appears I can't use rvm use
in a non-interactive session (i.e. in the crontab). (I tried it by sticking that in my bashrc
file and telling cron to look at my bashrc
file. I ended up forkbombing myself..)
如何通过 rvm 使用特定版本的 ruby 获取我的 crontab?
How do I get my crontab using a specific version of ruby via rvm?
推荐答案
来自 tty 切换 ruby 版本:
From tty switch ruby version:
rvm use 1.9.3
您应该使用 rvm 设置 cron:
You should set up cron with rvm:
rvm cron setup
那么您的 crontab 将如下所示:
then your crontab would look like this:
<代码>PATH="/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/local/rvm/gems/ruby-1.9.3-p194/bin:/usr/local/rvm/gems/ruby-1.9.3-p194@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p194/bin:/usr/local/rvm/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/rvm/gems/ruby-1.9.3-p194@global/"
rvm_env_string='ruby-1.9.3-p194'
rvm_path='/usr/local/rvm'
rvm_ruby_string='ruby-1.9.3-p194'
RUBY_VERSION='ruby-1.9.3-p194'
GEM_HOME='/usr/local/rvm/gems/ruby-1.9.3-p194'
GEM_PATH='/usr/local/rvm/gems/ruby-1.9.3-p194:/usr/local/rvm/gems/ruby-1.9.3-p194@global'
MY_RUBY_HOME='/usr/local/rvm/rubies/ruby-1.9.3-p194'
IRBRC='/usr/local/rvm/rubies/ruby-1.9.3-p194/.irbrc'
Cron 将使用 1.9.3 ruby 与上述内容
Cron would use 1.9.3 ruby with the above
刚刚注意到我的文本在 SO 上的格式不正确,所以我重新格式化了它
Just noticed my text was not well formatted on SO, so I have reformatted it
这篇关于使用特定版本的 ruby 在 cron 上运行 gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!