[LRUG] Rake binstub

Gerhard Lazu gerhard at lazu.co.uk
Thu Oct 9 15:07:18 PDT 2014


The Rubyist in you
​senses
 an SRP violation. The cron knows too much about the inner workings of your
app. A shim script in the app itself that the cron invokes directly will
solve it:

#/bin/bash -e

exec 3> >(logger -t cron.app.rake) 1>&3 2>&3 # Logs stdout and stderr to
syslog with cron.app.rake tag
                                             # ... because there is nothing
worse than cron jobs that don't log to syslog!

APP_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # the
equivalent in Ruby: File.expand_path("../", __FILE__)
                                                            # if the script
itself is a symlink, see SO for a beefed up version

cd $APP_DIR                # you're in your app's root dir, carry on
echo "bundle exec rake..." # substitute for the actual command

Your app now exposes an executable that anything can call, without knowing
anything about Rake, app path or any other app specific detail.

Gerhard


------------------------------
Twitter <http://twitter.com/#!/gerhardlazu> Github
<https://github.com/gerhard> Blog <http://gerhard.lazu.co.uk/>

On Thu, Oct 9, 2014 at 11:08 AM, Andrew Stewart <boss at airbladesoftware.com>
wrote:

> On 9 Oct 2014, at 11:36, Stephen Best <bestie at gmail.com> wrote:
> > I'm not sure what the virtue of removing the `cd` step from your cronjob
> is. It sounds way more trouble than it's worth. However this was
> interesting to think about the answers were great also.
>
> I was mainly trying to understand why rake couldn't be run from outside
> its path.
>
> Most unix programs can be run from wherever you like on the file system;
> the program figures out its own location, if necessary, and does its
> thing.  In contrast rake needs you to be in the project's top-level
> directory, or a subdirectory.  I've never tried to run rake from outside a
> project's directory, so I hadn't encountered this constraint before.
>
> Cheers,
> Andy
> _______________________________________________
> Chat mailing list
> Chat at lists.lrug.org
> Archives: http://lists.lrug.org/pipermail/chat-lrug.org
> Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org
> List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20141009/5bb82fd4/attachment-0003.html>


More information about the Chat mailing list