0

I am trying to run the command: su - <username> -c RAILS_ENV=production rake assets:precompile as root, even though ruby, rvm and all gems were installed as an another user. Thats because, I have lost access to the computer from which I could login to the server with that username.

So when I run the above command, I get the following error:

rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)

I am in the rails app directory when executing the above command. ls gives me:

Gemfile       README.rdoc  app  config     db   log  public  test  vendor
Gemfile.lock  Rakefile     bin  config.ru  lib  migrate  solr    tmp

Similarily if I do: su - <username> -c "bundle", I get the error: Could not locate Gemfile.

I have read posts on SO such as Link #1, Link #2, Link #3, Link #4, but none have been able to resolve the issue.

Please if someone knows the method to resolve this and can give me an answer that will be a huge relief.

Community
  • 1
  • 1
codingbear
  • 296
  • 5
  • 18

1 Answers1

0

Since you installed rvm as another user, all your gems and such will be placed in that user's home directory, as will the actual version of ruby you're using. In order to get everything working as root, you'd either need to reinstall rvm system-wide and set things up that way, or you could try getting RVM running as root.

When you install rvm, it adds the following lines to the user's ~/.bash_profile, so you could try adding this to root's:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

Here, you'd need to substitute $HOME for /home/username, where username is the user that has rvm installed. Otherwise, it would default to the home directory of the currently logged in user, which would be /root.

Another idea, you say you lost access to the computer you could log in as that user from. But, if you can log in as root, you can change anything in the system. Assuming it's an ssh key issue, why not just add your current computer's ~/.ssh/id_rsa.pub to the user's ~/.ssh/authorized_keys as root, and then log in and execute commands as that user as you originally intended?

take
  • 319
  • 3
  • 8
  • Hi @take, Thanks for responding to my question so quickly. I had to get up from the computer after being frustrated from this issue for some while, and it was a pleasant surprise to see your response, when I returned. I added the lines you mentioned to the root's .bash_profile (and substituted the needed username), but still the command gave the same error of Rakefile not found. I am going to try the another idea you suggested. Just wanted to ask that when I add my current computers id_rsa.pub to the lost user's .ssh/authorized_keys, do I delete the line with the previous user's entry? – codingbear Jan 12 '16 at 02:26
  • 1
    Hi @take, your idea of adding my current user's ~/.ssh/id_rsa.pub worked. How awesome was that. Thanks so much man. – codingbear Jan 12 '16 at 05:01
  • No problem, glad I could help! You certainly could remove the old computer's public key, especially if you're concerned with someone else gaining access to the system. – take Jan 13 '16 at 03:25
  • oh yeah that's another great suggestion again from you. Thanks mate. Will do that. – codingbear Jan 13 '16 at 06:56