0

I have a script that commits my code to GitHub and I modified it to also run a script on the web server that is supposed to pull the new code, which it does successfully, but then is unable to run the necessary Rails commands like Rake or Bundle. I'm confused because I change to the project directory at the top of the script and git pull runs fine. I even tried putting the Rails command calls inside a subshell with cd /home/rails/ at the top but that still didn't work and neither did specifying the full path to each Rails script. Am I going about this the wrong way or is there a better way to automate these two processes?

Commit script:

git add -A
git commit -m "$1"
git push
ssh [email protected] sh /home/rails/update_script.sh

Update script on server:

service unicorn stop
cd /home/rails/
git pull
rake db:migrate RAILS_ENV=production
rake assets:precompile RAILS_ENV=production
bundle install
service unicorn start
exit

Edit: Oops, forgot the output. Here is the output from the server:

 * Stopping Unicorn web server unicorn
   ...done.
From https://github.com/my_name/example
   7e0fee4..17fd564  master     -> origin/master
Updating 7e0fee4..17fd564
Fast-forward
 fresh.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
/usr/bin/env: ruby: No such file or directory
/usr/bin/env: ruby * Starting Unicorn web server unicorn
: No such file or directory
/usr/bin/env: ruby: No such file or directory
   ...done.
6
  • 1
    What specifically happens when your commit script tries to run the update script? Do you get any error messages? Commented Feb 5, 2015 at 2:49
  • Yes, sorry, forgot to post output. It is now located above. Commented Feb 5, 2015 at 2:54
  • 1
    It looks like the big problem is that ruby isn't in your command path on the server. What directory is the ruby executable in, and how is that directory normally added to the command path? Commented Feb 5, 2015 at 3:09
  • I'm using RVM so the output for which ruby is /usr/local/rvm/rubies/ruby-2.1.5/bin/ruby. Ruby and Rails are both working fine when I visit the website or when I log onto the server manually, I can run IRB, the Rails console, rake, bundler, all through SSH, with working aliases for just about everything. Everything works fine aside from these rake and bundler commands inside this script. Commented Feb 5, 2015 at 3:26
  • 1
    Okay, how is /usr/local/rvm/rubies/ruby-2.1.5/bin normally added to root's command path? I'm guessing it's in root's .bash_profile? Commented Feb 5, 2015 at 3:30

1 Answer 1

1

Maybe you have to add /usr/local/rvm/rubies/ruby-2.1.5/bin to $PATH.

And I think you should run bundle install before running rake tasks.

Try this:

service unicorn stop
cd /home/rails/
git pull
export PATH=$PATH:/usr/local/rvm/rubies/ruby-2.1.5/bin
bundle install
RAILS_ENV=production bundle exec rake db:migrate
RAILS_ENV=production bundle exec rake assets:precompile
service unicorn start
exit
Sign up to request clarification or add additional context in comments.

1 Comment

Now I'm getting this: rake aborted! Could not find rake-10.4.2 in any of the sources /home/rails/config/boot.rb:4:in <top (required)>' /home/rails/config/application.rb:1:in <top (required)>' /home/rails/Rakefile:4:in <top (required)>' (See full trace by running task with --trace) /home/rails/fresh.sh: 15: /home/rails/fresh.sh: bundle: not found Which doesn't make sense as I already have these gems installed in the very same directory that this script is saved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.