[英]What is the correct way to run a custom ruby script from inside the script directory from Rails application? (Production environment)
I tried all of the answers from the above stack overflow post but none of them worked 我尝试了上述堆栈溢出帖子中的所有答案,但没有一个起作用
When I replace the #!/usr/bin/env ruby with the #!/path/to/my/script/runner and try to run 当我用#!/ path / to / my / script / runner替换#!/ usr / bin / env ruby并尝试运行时
Rails returns: Rails返回:
/var/www/cmgmail/production/releases/20100810151610/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in establish_connection': Please install the postgresql adapter:
gem install activerecord-postgresql-adapter (no such file to load -- pg) (RuntimeError) from /var/www/cmgmail/production/releases/20100810151610/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in
establish_connection' etc. . /var/www/cmgmail/production/releases/20100810151610/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in Establishment_connection
establish_connection': Please install the postgresql adapter:
gem install activerecord-postgresql-adapter (no such file to load -- pg) (RuntimeError) from /var/www/cmgmail/production/releases/20100810151610/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:in
建立连接中等。 . 。 .
。
when I leave the original shebang #!/usr/bin/env ruby intact, no combination of commands work. 当我保留原始的shebang#!/ usr / bin / env ruby完好无损时,没有任何命令组合有效。
eg script/my_script -e production returns: 例如script / my_script -e生产返回:
/var/www/cmgmail/production/releases/20100810151610/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:62:in establish_connection': development database is not configured (ActiveRecord::AdapterNotSpecified) from /var/www/cmgmail/production/releases/20100810151610/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in
establish_connection' ...etc /var/www/cmgmail/production/releases/20100810151610/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:62:in Establishment_connection
establish_connection': development database is not configured (ActiveRecord::AdapterNotSpecified) from /var/www/cmgmail/production/releases/20100810151610/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in
建立establish_connection': development database is not configured (ActiveRecord::AdapterNotSpecified) from /var/www/cmgmail/production/releases/20100810151610/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in
'...等
./my_script returns: ./my_script: No such file or directory (yet I verified the file is there) ./my_script返回:./my_script:没有这样的文件或目录(但我已确认文件在那里)
is there something obvious I am missing? 有什么明显的我想念的吗?
I suppose I can make this into a rake task but this script runs fine in dev mode. 我想我可以将其变成rake任务,但是此脚本在dev模式下运行良好。
Don't forget to run chmod a+x my_script
. 不要忘记运行
chmod a+x my_script
。 By the way, try running script/my_script
with the RAILS_ENV=production
environment variable. 顺便说一句,尝试使用
RAILS_ENV=production
环境变量运行script/my_script
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.