9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

zsh+rbenv+crontab @wheneverで「no such file to load -- bundler/setup (LoadError)」等のエラー回避法

Last updated at Posted at 2015-09-04

#.zshrc
rbenvwheneverなどはbashを前提として説明してあるので、zshに切り替えた場合そのままでは機能しない

# .zshrcへ追加
export PATH=$HOME/.rbenv/shims:$PATH
if which rbenv > /dev/null; then eval "$(rbenv init - zsh)"; fi

"$(rbenv init - zsh)"がポイント

rbenv

変更点なし

crontab

# crontab -e で編集して以下をファイル先頭に追加

SHELL=/path/to/your/zsh # which zsh のパス

cronのデフォルトのSHELL/bin/shなので変更する

whenever

デフォルトのjob typeはこちら

set :job_template, "bash -l -c ':job'"

job_type :command, ":task :output"
job_type :rake,    "cd :path && :environment_variable=:environment bundle exec rake :task --silent :output"
job_type :runner,  "cd :path && bin/rails runner -e :environment ':task' :output"
job_type :script,  "cd :path && :environment_variable=:environment bundle exec script/:task :output

config/schedule.rbの中で次のものだけ上書きする

# Use this file to easily define all of your cron jobs.
#
# It's helpful, but not entirely necessary to understand cron before proceeding.
# http://en.wikipedia.org/wiki/Cron

# Example:
# ...
# ...
# ...

set      :job_template, "source $HOME/.zshrc; $(which zsh) -l -c ':job'"
job_type :runner,       "cd :path && bundle exec rails runner -e :environment ':task' :output"

.zshrcをソースして、シェルをzshがインストールされているパス$(which zsh)で指定し、さらにrunnerbundle exec rails ...へ変更

これにてタイトルのようなエラーが回避出来る

9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?