【问题标题】:Running RAILS_ENV=production with the system command使用系统命令运行 RAILS_ENV=production
【发布时间】:2014-12-07 03:22:30
【问题描述】:

我在服务器上运行的脚本遇到了一个非常奇怪的问题,详细信息如下。但本质上,我正在使用脚本来设置 Rails 应用程序,并且我正在从现有的 Rails 应用程序中调用该脚本。

在我现有的应用程序(调用服务器上的脚本的应用程序)中,我有:-

Spawnling.new do
   system "cd ~/ && ~/*/create_site.sh param1 param2 >> /tmp/logger"
end

create_site.sh 脚本使用以下内容创建全新的 rails 安装:

rails new $DIR --database postgresql

然后它会做很多事情来设置应用程序。问题是脚本似乎运行得非常好,直到它到达以下命令:

cd $DIR && RAILS_ENV=production rails g roroacms:install -v && RAILS_ENV=production rake assets:clean && RAILS_ENV=production rake assets:precompile

这真的很奇怪,因为当我以 root 用户身份手动运行 top 命令时,它似乎运行得非常好,完全没有任何问题。当我在顶部命令末尾查看记录器文件时,它如下所示:

Your bundle is updated!
Bundle is installed and up to date
RoroaCMS installation
Installation complete with assets
Server started

当我手动运行它时,它会在运行命令的每一行之间输出一些消息。对此有什么想法吗?我认为这可能与 RAILS_ENV 有关,因为 rails new 命令在脚本的早期运行良好。

【问题讨论】:

  • 您是否以 root 身份运行脚本?
  • 好吧,当我以 root 身份手动运行它时,它可以正常工作,但是当我在 cron 或上述命令中运行命令时,它在 rails g roroacms:install 失败我认为这可能是这样做,但没有错误消息,所以很难调试

标签: ruby-on-rails ruby bash nginx centos


【解决方案1】:

您好,我在服务器上编写了大量脚本,我总是使用bundle exec rails g rspec:install production 格式,因此您的命令将是cd $DIR && bundle exec rails g roroacms:install -v production && bundle exec rake assets:clean production && bundle exec rake assets:precompile production。我没有太多理由支持它,但这种格式似乎在不同的服务器环境中最可靠。

【讨论】:

    猜你喜欢
    • 2015-09-29
    • 1970-01-01
    • 2019-10-12
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-25
    相关资源
    最近更新 更多