首頁  >  問答  >  主體

ruby - whenever+crontab 提示 not found gem ,check GEM_PATH問題

1.我使用whenever gem 來定時啟動 rails runner 任務;可是定時任務的log顯示:

/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'railties' (>= 0.a) among 17 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/gems/2.3.0:/root/.gem/ruby/2.3.0', execute `gem env` for more information
        from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
        from /usr/local/rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
        from /usr/local/rvm/gems/ruby-2.3.0/bin/rails:22:in `<main>'
        from /usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
        from /usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
        

我也gem install railties了,可是還是這樣,我的ruby version:2.3.0,rails version:4.1.0;
本人ruby 小白,求幫助

阿神阿神2758 天前890

全部回覆(1)我來回復

  • 阿神

    阿神2017-04-25 09:04:32

    自問自答來更新答案,原來是「whenever +cron」的坑,原因是cron中沒有加入關於 GEM_PATH的參數,

    1.crontab -l
    [root@meituanQaServer1 qa_assist]# crontab -l
    # Begin Whenever generated tasks for: /root/guoshun/qa_assist/config/schedule.rb
    PATH=/usr/local/rvm/gems/ruby-2.3.0/bin:/usr/local/rvm/gems/ruby-2.3.0@global/bin:/usr/local/rvm/rubies/ruby-2.3.0/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/rvm/bin:/usr/local/apache-maven/bin:/usr/local/python27/bin/:/root/bin:/usr/local/python27/bin
    
    GEM_PATH=/usr/local/rvm/gems/ruby-2.3.0:/usr/local/rvm/gems/ruby-2.3.0@global
    
    0 16 27 * * /bin/bash -l -c 'cd /root/guoshun/qa_assist && rails runner -e production Device.send_device_message >> elephant.log 2>&1'
    
    0 0,3,6,9,12,15,18,21 * * * /bin/bash -l -c 'cd /root/guoshun/qa_assist && rails runner -e production JiraData.get_jira_data_status >> workflow.log 2>&1'
    
    30 22 * * * /bin/bash -l -c 'cd /root/guoshun/qa_assist && python hiveDaily/runner.py >> cron.log 2>&1'
    
    * 20 * * * /bin/bash -l -c 'cd /root/guoshun/ht_plat/ && python deviceAnalysis/runner.py >> device.log'
    
    # End Whenever generated tasks for: /root/guoshun/qa_assist/config/schedule.rb

    中看看有沒有加入GEM_PATH參數,如果沒有

    [root@meituanQaServer1 qa_assist]# echo $GEM_PATH
    /usr/local/rvm/gems/ruby-2.3.0:/usr/local/rvm/gems/ruby-2.3.0@global

    3.crontab -e 編輯 cron表,新增:

    GEM_PATH=/usr/local/rvm/gems/ruby-2.3.0:/usr/local/rvm/gems/ruby-2.3.0@global//上面输出的路径

    大功告成了。

    回覆
    0
  • 取消回覆