bingo bob
2009-Aug-31 12:52 UTC
Running a rake task from cron on a shared webhost (joyent)
I''ve created a cron task via my webhost''s (a joyent shared accelerator) cron control panel. The control panel has a "run now" button, when I hit this button the thing works, I get my nice backup file created in /db, all fine. Thing is when I leave the job to run over night, all it creates is an empty db backup file! Here''s the the crontab line... 11 3 * * * cd /users/home/foo/domains/foo.com/web && RAILS_ENV=production /usr/local/bin/rake db:mysql:backup #foo nightly backup What gives? -- Posted via http://www.ruby-forum.com/.
Colin Law
2009-Aug-31 13:05 UTC
Re: Running a rake task from cron on a shared webhost (joyent)
2009/8/31 bingo bob <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > > I''ve created a cron task via my webhost''s (a joyent shared accelerator) > cron control panel. The control panel has a "run now" button, when I hit > this button the thing works, I get my nice backup file created in /db, > all fine. Thing is when I leave the job to run over night, all it > creates is an empty db backup file! > > Here''s the the crontab line... > > 11 3 * * * cd /users/home/foo/domains/foo.com/web && > RAILS_ENV=production /usr/local/bin/rake db:mysql:backup #foo nightly > backup >Could be an issue with not being logged in? Permissions or path or something? Colin
bingo bob
2009-Aug-31 13:13 UTC
Re: Running a rake task from cron on a shared webhost (joye
Maybe, just unsure what. Annoying as it''s stopping me doing lots of rake stuff on a schedule. I mean I know there are solutions to run background tasks in the app but I didn''t really want the memory overhead for now and this seems like a quick win. If "only" I could get it working! Any ideas what else I could try anyone? -- Posted via http://www.ruby-forum.com/.
Colin Law
2009-Aug-31 13:20 UTC
Re: Running a rake task from cron on a shared webhost (joye
2009/8/31 bingo bob <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>:> > > Maybe, just unsure what. Annoying as it''s stopping me doing lots of rake > stuff on a schedule. > > I mean I know there are solutions to run background tasks in the app but > I didn''t really want the memory overhead for now and this seems like a > quick win. If "only" I could get it working! > > Any ideas what else I could try anyone? > --As you snipped everything and the message seems to have become de-threaded no-one except possibly me will know what this message is about. Colin
Are you not able to see the output of the cron job? The output should be logged somewhere or sent in an email - that depends on your hosting environment. If you can''t find that, you could move your command to a shell script that is referenced by the crontab. You can add code in that script to inspect the environment and/or capture the output of your rake command in your own log file. But you could use a little more information to help track down the problem. On Aug 31, 6:13 am, bingo bob <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Maybe, just unsure what. Annoying as it''s stopping me doing lots of rake > stuff on a schedule. > > I mean I know there are solutions to run background tasks in the app but > I didn''t really want the memory overhead for now and this seems like a > quick win. If "only" I could get it working! > > Any ideas what else I could try anyone? > -- > Posted viahttp://www.ruby-forum.com/.
bingo bob
2009-Sep-02 08:27 UTC
Re: Running a rake task from cron on a shared webhost (joye
Thanks to all. I got this working in the end - the problem was with my rake db:mysql:backup, it specfied the path to the mysqldump command, and I don''t know why but when cron ran the command it failed due to this path (when the rake task was run directly from the command line it worked out). I ran "which mysqldump" and then specified that path explicitly in the rake task - and all is good! All is fine (I think). But now on to stage two, all I''ve done so far with my single rake task run from cron is create the backup file nightly. I now need to manage these backups (cull the oldest and make a copy on another machine). I figure I can use this command for the cull (or something like it).. /usr/bin/find PATHTORAILSAPP/db/*.gz -mtime +14 -exec rm {} \; and a nightly scp command to copy the files off the machine to another machine. Thing is, should I write rake tasks to do this stuff (how easy is that) or should I run the commands from cron? Any and all tips appreciated. I''ve done the first bit, so at least I''ve got backups happening nightly (phew)! -- Posted via http://www.ruby-forum.com/.
Felix Schäfer
2009-Sep-02 08:39 UTC
Re: Running a rake task from cron on a shared webhost (joye
Am 02.09.2009 um 10:27 schrieb bingo bob:> I > don''t know why but when cron ran the command it failed due to this > pathcron on linux doesn''t preserve environment variables, nor does it read global ones (/etc/profile.d and others), i.e. if you need some, you have to set them up yourself. Further information in ''man crontab'' http://linux.die.net/man/5/crontab Best regards, Felix
bingo bob
2009-Sep-02 16:08 UTC
Re: Running a rake task from cron on a shared webhost (joye
Felix Schäfer wrote:> Am 02.09.2009 um 10:27 schrieb bingo bob: > >> I >> don''t know why but when cron ran the command it failed due to this >> path > > > cron on linux doesn''t preserve environment variables, nor does it read > global ones (/etc/profile.d and others), i.e. if you need some, you > have to set them up yourself. Further information in ''man crontab'' > http://linux.die.net/man/5/crontab > > Best regards, > > FelixOk well that makes sense then - noted. Any tips on the backup side of things? -- Posted via http://www.ruby-forum.com/.