Setting path for whenever in cron so it can find ruby
The solution is to put this in schedule.rb
:
env :PATH, ENV['PATH']
Here's a little guide I put together on the topic.
How to set PATH variable in crontab via whenever gem
Ok, it seems as I found the solution. I found it here: https://gist.github.com/jjb/950975
I will update this answer when I have tested it
I have to put this into my schedule.rb
# If your ruby binary isn't in a standard place (for example if it's in /usr/local/bin,
# because you installed it yourself from source, or from a thid-party package like REE),
# this tells whenever (or really, the rails runner) where to find it.
env :PATH, '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin'
Whenever gem cronjob not loading PATH from /etc/environment
In the end adding source /etc/environment
to the .bash_profile
(not .bashrc
) ensures that the cron user loads the right variables and it is working now
Can't get Ruby Whenever working
I think the problem may have had to do with rvm
and the .rvmrc
file I had set up which loaded the correct rvm
settings when I cd
into the directory.
In attempting to ensure that the command was working opened a new terminal window and ran: bash -l -c 'cd /Users/me/apps/Test && bundle exec bin/rails runner -e development '\''Test.new.run'\'' >> /Users/me/apps/Test/log/cron.log 2>&1'
The first thing that came up was the standard 1 off rvm message:
You are using '.rvmrc', it requires trusting, it is slower and it is not compatible with other ruby managers,
you can switch to '.ruby-version' using 'rvm rvmrc to ruby-version'
or ignore this warning with 'rvm rvmrc warning ignore /Users/me/apps/Test/.rvmrc',
'.rvmrc' will continue to be the default project file in RVM 1 and RVM 2,
to ignore the warning for all files run 'rvm rvmrc warning ignore all.rvmrcs'.
********************************************************************************
* NOTICE *
********************************************************************************
* RVM has encountered a new or modified .rvmrc file in the current directory, *
* this is a shell script and therefore may contain any shell commands. *
* *
* Examine the contents of this file carefully to be sure the contents are *
* safe before trusting it! *
* Do you wish to trust *
* '/Users/me/apps/Test/.rvmrc'? *
* Choose v[iew] below to view the contents *
********************************************************************************
y[es], n[o], v[iew], c[ancel]>
Once I typed y
and hit enter, the cron jobs are now executing properly.
Unfortunately, I'm still not seeing anything in my cron.log
file.
Related Topics
What Does "+=" (Plus Equals) Mean
Ruby Gsub Multiple Characters in String
Detect If Application Was Started as Http Server or Not (Rake Task, Rconsole etc)
How to Access Nested Elements of a Hash with a Single String Key
Ruby Difference in Array Including Duplicates
Using $ Sudo Bundle Exec ... Raises 'Bundle: Command Not Found' Error
How to Get a Backtrace from a Systemstackerror: Stack Level Too Deep
Storing Arrays in Database Using Activerecord
Ruby (And Rails) Nested Module Syntax
Ruby Gets/Puts Only for Strings
How to Install Redcloth on Windows
Optional Arguments with Default Value in Ruby
Functional Code Examples in Ruby