Can you run a rails console or rake command in the

2019-01-31 07:04发布

I have set up a RoR environement on AWS' elastic beanstalk. I am able to ssh into my EC2 instance. My home directory is /home/ec2-user, which is effectively empty. If I move up a directory, there is also a /home/webapp directory that i do not have access to.

Is there a way to run a rake command or rails console on my elastic beanstalk instance?

If I type rails console I get Usage: rails new APP_PATH [options] If I type RAILS_ENV=production bundle exec rails console, I get "Could not locate Gemfile"

7条回答
闹够了就滚
2楼-- · 2019-01-31 07:08

I like to create an eb_console file at the root of my rails app, then chmod u+x it. It contains the following:

ssh -t ec2-user@YOUR_EC2_STATION.compute.amazonaws.com  'cd /var/app/current && bin/rails c'

This way, I just have to run:

./eb_console

like I would have run heroku run bundle exec rails c.

查看更多
forever°为你锁心
3楼-- · 2019-01-31 07:09

You have to find the folder with your Gemfile :p.

To do that, I would take a look in you web server config there should be a config that tells you where your app directory is.

Maybe you know where your app is.

But in case you don't know, I would give a try to:

grep -i your_app_name /etc/apache/*
grep -i your_app_name /etc/apache/sites-enabled/*

To search files containing your_app_name in Apache config.

Or if you are using nginx, replace apache above by nginx.

after you find application folder, cd into it and run RAILS_ENV=production bundle exec rails c.

Making sure that your application is configured to run in production in Apache or nginx configuration.

查看更多
Bombasti
4楼-- · 2019-01-31 07:13

Don't know why, but since EBS runs everything as root, this worked for me:

sudo su
bundle exec rails c production
查看更多
Deceive 欺骗
5楼-- · 2019-01-31 07:15

None of these were working for me, including the aws-console script. I finally ended up creating a script directory in /var/app/current and then creating a rails file in that directory as outline by this answer on another SO question.

eb ssh myEnv
cd /var/app/current
sudo mkdir script
sudo vim script/rails

Add this to file and save:

echo #!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.

APP_PATH = File.expand_path('../../config/application',  __FILE__)
require File.expand_path('../../config/boot',  __FILE__)
require 'rails/commands'

Then make it executable and run it:

sudo chmod +x script/rails
sudo script/rails console

And it worked.

查看更多
倾城 Initia
6楼-- · 2019-01-31 07:24

For rails, jump to /var/app/current then as @juanpastas said, run RAILS_ENV=production bundle exec rails c

查看更多
姐就是有狂的资本
7楼-- · 2019-01-31 07:27

None of the other answers worked for me so I went looking - this is working for me now on an elastic beanstalk 64bit amazon linux 2016.03 V2.1.2 ruby 2.2 (puma) stack

cd /var/app/current
sudo su
rake rails:update:bin
bundle exec rails console

that returns me the expected console

Loading production environment (Rails 4.2.6)
irb(main):001:0>
查看更多
登录 后发表回答