Last active
August 29, 2015 14:04
-
-
Save serg-kovalev/7576c073c2ca94aa6ec5 to your computer and use it in GitHub Desktop.
RVM wrapper that loads needed environment in CRON tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# usage | |
# rvm_env_wrapper /path/to/project some_ruby_file.rb | |
# rvm_env_wrapper /path/to/project some_comand arg1 arg2 arg3 etc | |
# OR | |
# rvm_env_wrapper --use ruby_version@gemset_name some_comand_or_file | |
# Permissions: | |
# sudo chown user:group rvm_env_wrapper | |
# sudo chmod 774 rvm_env_wrapper | |
# | |
export HOME=/home/user | |
export RAILS_ENV=production | |
# Load RVM into a shell session *as a function* | |
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then | |
source "$HOME/.rvm/scripts/rvm" | |
else | |
echo "ERROR: An RVM installation was not found." 1>&2 | |
exit -1 | |
fi | |
if [[ -d "$1" ]] ; then | |
# Control will enter here if $1 (app directory) exists. | |
APP_DIR=$1 | |
shift | |
# Load RVM environment for the app | |
cd $APP_DIR | |
elif [ "$1" == "--use" ]; then | |
shift | |
rvm use $1 | |
shift | |
else | |
echo "Usage:" | |
echo "$0 PROJECT_DIR_PATH[or --use ruby-version@gemset] [args*]" | |
echo "ERROR: wrong usage" 1>&2 | |
exit -1 | |
fi | |
if [ $# -gt 0 ]; then | |
$* | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment