首页 文章

你能在弹性beanstalk环境中运行rails控制台或rake命令吗?

提问于
浏览
42

我在AWS'弹性beanstalk上 Build 了一个RoR环境 . 我能够进入我的EC2实例 . 我的主目录是/ home/ec2-user ,实际上是空的 . 如果我向上移动目录,还有一个我无法访问的 /home/webapp 目录 .

有没有办法在弹性beanstalk实例上运行 rake 命令或 rails console

如果我输入 rails console 我得 Usage: rails new APP_PATH [options] 如果我输入 RAILS_ENV=production bundle exec rails console ,我得到“ Could not locate Gemfile

7 回答

  • 0

    对于rails,跳转到 /var/app/current 然后@juanpastas说,运行 RAILS_ENV=production bundle exec rails c

  • -1

    不知道为什么,但由于EBS以root身份运行所有内容,这对我有用:

    sudo su
    bundle exec rails c production
    
  • 39

    这里提到的这些解决方案都没有为我工作,所以我编写了一个脚本/ aws-console中的一个小脚本 .

    您可以以root身份从/ var / app / current目录运行它:

    eb ssh
    cd /var/app/current
    sudo script/aws-console
    

    我的脚本可以找到Gist here .

  • 3

    没有其他的答案对我有用,所以我去寻找 - 这对我来说现在在弹性beanstalk 64bit amazon linux 2016.03 V2.1.2 ruby 2.2(美洲狮)堆栈

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

    返回给我预期的控制台

    Loading production environment (Rails 4.2.6)
    irb(main):001:0>
    
  • 52

    我喜欢在我的rails应用程序的根目录下创建一个 eb_console 文件,然后是 chmod u+x 它 . 它包含以下内容:

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

    这样,我只需要运行:

    ./eb_console
    

    就像我会运行 heroku run bundle exec rails c .

  • 8

    这些都不适合我,包括aws-console脚本 . 我最终在 /var/app/current 中创建了一个 script 目录,然后在this answer on another SO question中创建了该目录中的 rails 文件 .

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

    将其添加到文件并保存:

    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'
    

    然后使其可执行并运行它:

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

    它奏效了 .

  • 14

    你必须找到你的Gemfile文件夹:p .

    要做到这一点,我会看看你的web服务器配置应该有一个配置,告诉你你的应用程序目录在哪里 .

    也许你知道你的应用程序在哪里 .

    但如果您不知道,我会尝试:

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

    在Apache config中搜索包含your_app_name的文件 .

    或者如果您使用的是nginx,请将 apache 替换为 nginx .

    找到应用程序文件夹后,cd进入它并运行 RAILS_ENV=production bundle exec rails c .

    确保您的应用程序配置为在Apache或nginx配置中的 生产环境 中运行 .

相关问题