我尝试使用 production.rb
使用Capistrano部署项目app_path = "home/spree/spree"
app_name = "spree"
# Set environment to development unless something else is specified
env = ENV["RAILS_ENV"] || "development"
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete documentation.
worker_processes 3
# listen on both a Unix domain socket and a TCP port,
# we use a shorter backlog for quicker failover when busy
listen "#{app_path}/current/tmp/sockets/#{app_name}.socket", backlog: 64
# Preload our app for more speed
preload_app true
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 30
#pid "#{app_path}/current/tmp/pids/unicorn.#{app_name}.pid"
pid "tmp/pids/unicorn.#{app_name}.pid"
# Production specific settings
if env == "production"
# Help ensure your application will always spawn in the symlinked
# "current" directory that Capistrano sets up.
#working_directory "#{app_path}/current"
working_directory ""
# feel free to point this anywhere accessible on the filesystem user
shared_path = "#{app_path}/shared"
stderr_path "#{shared_path}/log/unicorn.stderr.log"
stdout_path "#{shared_path}/log/unicorn.stdout.log"
end
before_fork do |server, worker|
# the following is highly recomended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection
if defined?(ActiveRecord::Base)
ActiveRecord::Base.connection.disconnect!
end
# Before forking, kill the master process that belongs to the .oldbin PID.
# This enables 0 downtime deploys.
old_pid = "#{server.config[:pid]}.oldbin"
if File.exists?(old_pid) && server.pid != old_pid
begin
Process.kill("QUIT", File.read(old_pid).to_i)
rescue Errno::ENOENT, Errno::ESRCH
# someone else did our job for us
end
end
end
after_fork do |server, worker|
# the following is *required* for Rails + "preload_app true"
if defined?(ActiveRecord::Base)
ActiveRecord::Base.establish_connection
end
# if preload_app is true, then you may also want to check and
# restart any other shared sockets/descriptors such as Memcached,
# and Redis. TokyoCabinet file handles are safe to reuse
# between any number of forked children (assuming your kernel
# correctly implements pread()/pwrite() system calls)
end
deploy.rb
# config valid only for Capistrano 3.1
lock '3.2.1'
set :stages, %w(production staging)
set :default_stage, "staging"
set :application, 'spree'
set :repo_url, 'git@github.com:brasilct/spree.git'
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }.call
set :branch, 'homol'
# Default deploy_to directory is /var/www/my_app
set :deploy_to, "/home/spree/spree"
# Default value for :scm is :git
set :scm, :git
# Default value for :format is :pretty
set :format, :pretty
# Default value for :log_level is :debug
set :log_level, :debug
set :ssh_options, {
verbose: :debug
}
# Default value for :pty is false
set :pty, true
# Default value for :linked_files is []
# set :linked_files, %w{config/database.yml}
# Default value for linked_dirs is []
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }
set :default_shell, '/bin/bash -l'
set :use_sudo, false
# Default value for keep_releases is 5
set :keep_releases, 5
# Rails specific options
set :rails_env, 'production' # If the environment differs from the stage name
set :migration_role, :db # Defaults to 'db'
set :conditionally_migrate, false # Defaults to false
set :assets_roles, [:web, :app] # Defaults to [:web]
# set :assets_prefix, 'prepackaged-assets' # Defaults to 'assets' this should match config.assets.prefix in your rails config/application.rb
# set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets} # If you need to touch public/images, public/javascripts and public/stylesheets on each deploy
# RVM
set :rvm_type, :user
set :rvm_ruby_version, '2.1.2'
set :rvm_custom_path, '/home/dev/.rvm'
namespace :deploy do
desc 'Restart application'
task :restart do
invoke 'unicorn:restart'
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
的Gemfile
group :development do
# Deploy
gem 'capistrano', '~> 3.1'
gem 'capistrano-rails', '~> 1.1', require: false
gem 'capistrano-bundler', '~> 1.1', require: false
gem 'capistrano-rvm', '~> 0.1', require: false
end
group :production do
gem 'unicorn', '~> 4.8.3'
gem 'unicorn-rails'
gem 'capistrano3-unicorn'
end
Capfile
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
# Includes 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
#
require 'capistrano/rvm'
require 'capistrano3/unicorn'
# require 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
但是,当我运行 cap production deploy 时,我总是遇到此错误 - > http://pastebin.com/wRAFxbz1
有人可以帮我解决错误。