Capistrano部署到错误的环境

时间:2014-12-10 10:19:30

标签: ruby-on-rails ruby passenger capistrano3

我开始使用Capistrano将我的Rails应用程序部署到不同的远程服务器,但是,使用cap production deploy部署到服务器会将我的RAILS_ENV设置为部署而不是生产。我尝试通过向environment.rb添加ENV['RAILS_ENV'] ||= 'production'来强制环境,但这似乎无法解决问题。我检查了乘客,Apache和Rails的production.log,除了不正确的环境部署外,似乎没有任何错误。我的Capistrano部署可能出现什么问题?

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

# 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

# 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 }

*文件中的字段填写正确的信息。

3 个答案:

答案 0 :(得分:1)

我可能是错的,但通常是Capistrano,只要它没有任何特殊的Apache或Nginx插件,按原样部署代码,你的问题似乎来自乘客配置。可能是它试图在错误的环境下运行服务器。我不记得它是如何使用Apache的,但是使用nginx你必须确保行

...
passenger_app_env production;
...

位于/opt/nginx/conf/nginx.conf

也许这可以帮助您设置Apache配置: https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#PassengerAppEnv

答案 1 :(得分:0)

production.rb你应该:

set :stage, :production

或者有人说这个选项在v3中不起作用(我正在使用v3并为我设置阶段工作),但是如果设置阶段不起作用,你可能想要阅读它:

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

答案 2 :(得分:0)

我能够解决我的问题。我的问题发生了,因为我忘记将生产secret_key_base添加为生产服务器中的环境变量。