Created
March 10, 2018 21:14
-
-
Save ndvbd/a4402e250462eeb0c5a770356bbcffb3 to your computer and use it in GitHub Desktop.
Running Rails Rake task from any user in any folder, by detecting the RVM environment
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
#!/bin/bash | |
# By default, passenger will run your app as the user who owns the config/environment.rb or config.ru file: https://stackoverflow.com/questions/4231711/what-user-is-running-my-rails-app | |
RAILS_USER=$(stat -c '%U' /YOUR_PATH_HERE/environment.rb) | |
echo "Detected rails user: $RAILS_USER" | |
sudo -H -u $RAILS_USER bash -c 'RAILS_USER=$USER; echo "I am $USER, with uid $UID" ; echo "whoamI: $(whoami)" ; echo "Running rvm script: /home/$RAILS_USER/.rvm/scripts/rvm" ; source /home/$RAILS_USER/.rvm/scripts/rvm ; ENV_FILE=`rvm env --path` ; echo $ENV_FILE ; source $ENV_FILE ; cd /YOUR_PATH_HERE/lib/tasks ; rake XXX:YYY RAILS_ENV=production' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment