whenever PATH in crontab file for rails 3 ubuntu
Asked Answered
Z

4

3

I am using whenever gem with rails 3. On my production server (ubuntu) , the runner task does not run. I tried setting the :set job_template to get -l -i as mentioned in this github ticket. However that does not solve the problem.

The problem on this particular production ubuntu is that the ruby path is not there in echo $PATH:

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Whereas the ruby path is /var/rails/myapp/shared/bundle/ruby/1.8/bin

So if I manually edit the crontab file and add PATH=/var/rails/myapp/shared/bundle/ruby/1.8/bin: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games to the crontab file, the runner task is executed correctly.

However every time I do a deploy, I need to manually edit the crontab file to add the PATH statement to it.

Is there any way in whenever to add this PATH line in crontab file, so that there would not be any need to do this manually after every deploy?

Thanks

Zoochore answered 18/4, 2011 at 2:44 Comment(0)
H
3

I am not using RVM and adding the below code in the file config/schedule.rb(place where u write whenever gem related code) worked for me.

env :PATH, ENV['PATH']
Harmony answered 15/4, 2013 at 9:15 Comment(0)
D
1

I think if you add /var/rails/myapp/shared/bundle/ruby/1.8/bin to the PATH of whatever user cron is running under on the server, it should be picked up. Or, you could add it in the whenever schedule.rb:

env :PATH, "$PATH:/var/rails/myapp/shared/bundle/ruby/1.8/bin"

That should do the trick, but I haven't tested it.

Dorsey answered 18/4, 2011 at 8:41 Comment(1)
Thanks ! Adding the /var/rails/myapp/shared/bundle/ruby/1.8/bin to the PATH of cron user or editing /etc/environment or bashrc for cron user does not work. It works only if the PATH statement is there in the crontab file. The env :PATH option that you have mentioned is adding the PATH line to the crontab file correctly. Just one problem is the syntax for adding $PATH. The current method is not expanding the $PATH value. So the line that gets entered in crontab file is PATH=$PATH:/var/rails/myapp/shared/bundle/ruby/1.8/bin.Zoochore
M
1

The answer from idlefingers looks mostly correct, but based on the comment from ami, I would change that line to the following:

env :PATH, "#{ENV["PATH"]}:/var/rails/myapp/shared/bundle/ruby/1.8/bin"

Notice the string interpolation for the environment key for PATH. I have not tested this, but based on ami's comment, this should fully expand the path string in the crontab file as expected.

Mellen answered 4/12, 2011 at 19:55 Comment(0)
I
0

Add the PATH statement to the top of the crontab file, before the line that starts

# BEGIN Whenever generated tasks for:

and you shouldn't have to manually edit your crontab file every time

Impeachable answered 2/7, 2011 at 23:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.