简体   繁体   English

Capistrano部署到错误的环境

[英]Capistrano Deploying to Wrong Enviornment

I started using Capistrano to deploy my Rails application to different remote servers, however, deploying to a server using cap production deploy sets my RAILS_ENV to deployment instead of production. 我开始使用Capistrano将Rails应用程序部署到不同的远程服务器,但是,使用cap production deploy部署到服务器将RAILS_ENV部署为部署而不是生产。 I have tried forcing the environment by adding ENV['RAILS_ENV'] ||= 'production' to the environment.rb, but that doesn't seem to fix the problem. 我已经尝试通过将ENV['RAILS_ENV'] ||= 'production'添加到environment.rb来强制环境,但这似乎无法解决问题。 I checked the production.log for Passenger, Apache, and Rails and nothing seems to be wrong, except for the incorrect environment deployment. 我检查了production.log中的Passenger,Apache和Rails,除了环境部署不正确外,似乎没有什么错。 What could be wrong with my Capistrano deployment? 我的Capistrano部署有什么问题?

production.rb production.rb

role :app, %w{deployer@*****}
role :web, %w{deployer@*****}
role :db,  %w{deployer@*****}

# Define server(s)
server '*****', user: 'deployer', roles: %w{web}

# SSH Options
# See the example commented out section in the file
# for more options.
set :ssh_options, {
    forward_agent: false,
    auth_methods: %w(password),
    password: '******',
    user: 'deployer',
}

deploy.rb deploy.rb

# Define the name of the application
set :application, 'app_pro'

# Define where can Capistrano access the source repository
# set :repo_url, 'https://github.com/[user name]/[application name].git'
set :scm, :git
set :repo_url, 'https://github.com/awernick/app_pros.git'

# Define where to put your application code
set :deploy_to, "/var/sentora/hostdata/zadmin/public_html/app_dir"
set :pty, true

set :format, :pretty

# Set the post-deployment instructions here.
# Once the deployment is complete, Capistrano
# will begin performing them as described.
# To learn more about creating tasks,
# check out:
# http://capistranorb.com/

# namespace: deploy do

#   desc 'Restart application'
#   task :restart do
#     on roles(:app), in: :sequence, wait: 5 do
#       # Your restart mechanism here, for example:
#       execute :touch, release_path.join('tmp/restart.txt')
#     end
#   end

#   after :publishing, :restart

#   after :restart, :clear_cache do
#     on roles(:web), in: :groups, limit: 3, wait: 10 do
#       # Here we can do anything such as:
#       # within release_path do
#       #   execute :rake, 'cache:clear'
#       # end
#     end
#   end

# end

Capfile Capfile

# Load DSL and set up stages
require 'capistrano/setup'

# Include default deployment tasks
require 'capistrano/deploy'

# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
#   https://github.com/capistrano/rvm
#   https://github.com/capistrano/rbenv
#   https://github.com/capistrano/chruby
#   https://github.com/capistrano/bundler
#   https://github.com/capistrano/rails
#   https://github.com/capistrano/passenger
#
# require 'capistrano/rvm'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
  require 'capistrano/bundler'
  require 'capistrano/rails'
  require 'capistrano/rails/assets'
  require 'capistrano/rails/migrations'
  require 'capistrano/passenger'

# Load custom tasks from `lib/capistrano/tasks' if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

*The fields in the files are filled out with the correct information. *文件中的字段已填写正确的信息。

I could be wrong, but normally Capistrano, as long as it does not have any special plugins for Apache or Nginx, deploys the code as it is, your problems appears to come from passenger configuration. 我可能是错的,但是通常Capistrano,只要它没有Apache或Nginx的任何特殊插件,就按原样部署代码,您的问题似乎出在乘客配置上。 It could be it tries to run the server under wrong environment. 可能是它试图在错误的环境下运行服务器。 I don't remember how it is with Apache, but with nginx you have to make sure the line 我不记得Apache的情况如何,但是使用nginx时,您必须确保

...
passenger_app_env production;
...

Is inside /opt/nginx/conf/nginx.conf 在/opt/nginx/conf/nginx.conf中

Maybe this could help you with setting up Apache config: https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#PassengerAppEnv 也许这可以帮助您设置Apache配置: https : //www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#PassengerAppEnv

In production.rb you should have: production.rb您应该具有:

set :stage, :production

or some say this option will not work in v3(I am using v3 and set stage works for me), however you might want to read this in case set stage doesn't work: 或有人说此选项在v3中不起作用(我正在使用v3并且set stage对我有效),但是如果set stage不起作用,您可能需要阅读以下内容:

http://dylanmarkow.com/blog/2014/01/08/capistrano-3-setting-a-default-stage/ http://dylanmarkow.com/blog/2014/01/08/capistrano-3-setting-a-default-stage/

I was able to resolve my problem. 我能够解决我的问题。 My problem was occurring because I forgot to add my production secret_key_base as an environment variable in my production server. 发生我的问题是因为我忘记将生产secret_key_base作为环境变量添加到生产服务器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM