Skip to content

Instantly share code, notes, and snippets.

@suwa320
Created August 19, 2012 13:00
Show Gist options
  • Select an option

  • Save suwa320/3394683 to your computer and use it in GitHub Desktop.

Select an option

Save suwa320/3394683 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ ! -d "$1" -o ! -f "$1/Gemfile" ]; then
echo Usage `basename $0` /path/to/app [command... ]
exit 1
fi
PATH=$HOME/.rvm/bin:$PATH
APP_DIR=$(cd $1 && pwd)
APP_NAME=`basename $APP_DIR`
LOGDIR=/tmp/$APP_NAME
LOGFILE=$LOGDIR/`date +%Y%m%d-%H%M%S`.log
COMMAND=`echo $* | cut -d ' ' -f 2-`
MAIL_ADDR=USER@EXAMPLE.COM
if [ ! -d "$LOGDIR" ]; then
mkdir -p $LOGDIR
fi
if [ -z "$RACK_ENV" ]; then
RACK_ENV=production
fi
if [ -z "$RVM_RUBY_VERSION" ]; then
RVM_RUBY_VERSION=default
fi
source "$HOME/.rvm/scripts/rvm"
rvm use $RVM_RUBY_VERSIO > /dev/null 2>&1
cd $APP_DIR
bundle exec $COMMAND > $LOGFILE 2>&1
if [ $? -ne 0 ]; then
cat $LOGFILE | mail -s "$APP_NAME return non-zero exit value" $MAIL_ADDR
fi
find $LOGDIR -mtime +14 -exec rm {} \;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment