Rails 请教一个折磨了我许久的问题有关 crontab rake 的问题

dadadada2x · July 15, 2013 · Last by dadadada2x replied at July 15, 2013 · 4304 hits

我在 crontab 中执行 rake 报错了 therubyracer 和 execjs 两个包我都装了,nodejs 我也在系统中装好了,执行 node -v 能看到 nodejs 的版本,但是执行 crontab 的时候还是报错 Warning: NLS_LANG is not set. fallback to US7ASCII. rake aborted! Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. /opt/app/ruby/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs/runtimes.rb:51:in autodetect' /opt/app/ruby/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs.rb:5:inmodule:ExecJS' /opt/app/ruby/lib/ruby/gems/1.9.1/gems/execjs-1.4.0/lib/execjs.rbin ' /opt/app/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.12/lib/active_support/dependencies.rb:240:inrequire' /opt/app/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.12/lib/active_support/dependencies.rb:240:in block in require' /opt/app/ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.1.12/lib/active_support/dependencies.rb:223:inblock in load_dependency' 感谢热心人的帮助,但是问题仍然没有解决 gem 'libv8', '~> 3.11.8'===libv8 (~> 3.11.8.12) gem 'execjs'==========execjs (>= 0.3.0) gem 'therubyracer'====therubyracer (0.11.4) 三个包都已经安装了 Gemfile.lock 中 (libv8 (~> 3.11.8.12),execjs (>= 0.3.0),therubyracer (0.11.4)) 系统中也安装完了 nodejs 了,我想问一下,我的 nodejs 是后安装的,难道我需要先卸载 execjs,therubyracer 库,然后在重新安装一遍么

我发现好像是环境变量的问题,我的配置是 export PATH=$PATH:/opt/ruby/bin,我加了一个 export PATH=$PATH:/usr/local/bin,就好使了

1 Floor has deleted

crontab 是怎么写的?sh 跟 bash 是不同的。

@chenge 我已经 gem install therubyracer -V 包中也都包含了 gem 'execjs' gem 'therubyracer' 按照网上的我也重新 bundle install 了,在项目下执行没有任何问题,项目也能启动起来,就是在 crontab 中不执行 #!/bin/bash export PATH=$PATH:/usr/local/bin 这些我在执行的时候都引用过了

#2 楼 @Rei 我的 sh 文件是这么写的 #!/bin/bash export PATH=$PATH:/usr/local/bin cd /abc && bundle exec rake RAILS_ENV=production sync:abc

bundle exec rake 前加上 PATH=xxxxxx 。 如果你用 whenever,那么用

job_type :rake, "cd :path;PATH=#{ENV['PATH']} bundle exec rake :task RAILS_ENV=production"

@zhangyuan 你说的 whenever 我试过了,理论上它只是生成的 crontab 其实跟 crontab 并没有什么区别,还是那个错误 Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. /home/web/config/application.rb:7:in <top (required)>' /home/web/Rakefile:5:inrequire' /home/web/Rakefile:5:in `'

#6 楼 @dadadada2x crontab 执行任务时,他的环境变量 PATH 的值,有可能和在命令行手动执行不同。我感觉是环境变量的问题。我上面的方法,就是为了在执行任务时,使用指定的 PATH

#7 楼 @zhangyuan 确实是环境变量的问题,已经解决了我又引了/usr/local/bin,十分感谢

You need to Sign in before reply, if you don't have an account, please Sign up first.