目前正在学习用 Capistrano3.1.0 来发布一个测试项目,发布的目标服务器是局域网内的一台机子,然后代码在 github。在完成了所有配置之后,运行了 cap production deploy,结果如下
rvm 1.25.20 (master) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.io/]
ruby-2.1.1
ruby 2.1.1p76 (2014-02-24 revision 45161) [i686-linux]
INFO [ffe2487d] Running /usr/bin/env mkdir -p /tmp/QYBUser/ on 192.168.1.4
INFO [ffe2487d] Finished in 0.128 seconds with exit status 0 (successful).
INFO Uploading /tmp/QYBUser/git-ssh.sh 100.0%
INFO [7d5305fc] Running /usr/bin/env chmod +x /tmp/QYBUser/git-ssh.sh on 192.168.1.4
INFO [7d5305fc] Finished in 0.122 seconds with exit status 0 (successful).
没有报错,但是项目根本没有发布上去...... 配置如下: 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 'capistrano/rbenv'
# require 'capistrano/chruby'
require 'capistrano/bundler'
require 'capistrano/rails'
# require 'capistrano/rails/assets'
# require 'capistrano/rails/migrations'
require 'whenever/capistrano'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
Dir.glob('lib/capistrano/**/*.rb').each { |r| import r }
unicorn
working_directory = "#{deploy_to}/#{application}/current"
app_path working_directory
#listen "/tmp/#{application}.sock", :backlog => 256
listen "127.0.0.1:8080"
timeout 300
pid "#{deploy_to}/#{application}/shared/pids/unicorn.pid"
stderr_path "#{deploy_to}/#{application}/shared/log/unicorn.stderr.log"
stdout_path "#{deploy_to}/#{application}/shared/log/unicorn.stdout.log"
preload_app true
if GC.respond_to?(:copy_on_write_friendly=)
GC.copy_on_write_friendly = true
end
before_fork do |server, worker|
ENV['BUNDLE_GEMFILE'] = "#{working_directory}/Gemfile"
old_pid = "#{deploy_to}/#{application}/shared/pids/unicorn.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
puts "Send 'QUIT' signal to unicorn error!"
end
end
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
after_fork do |server, worker|
ActiveRecord::Base.establish_connection
end
config/deploy/production.rb
set :stage, :production
set :branch, :master
set :rvm_type, :system
set :rvm_ruby_version , '2.1.1'
#role :app, %w{192.168.1.4}
#role :web, %w{192.168.1.4}
#role :db, %w{192.168.1.4}
# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server
# definition into the server list. The second argument
# something that quacks like a hash can be used to set
# extended properties on the server.
set :full_app_name, "#{fetch(:application)}"
server '192.168.1.4', user: 'deployer', roles: %w{web app db}, primary: true
set :deploy_to, "/var/projects/QYBUser"
set :rails_env, :production
set :unicorn_worker_count, 5
set :enable_ssl, false
conifg/deploy.rb
# config valid only for Capistrano 3.1
lock '3.1.0'
set :application, 'QYBUser'
set :deploy_user, 'deployer'
set :repo_url, '[email protected]:cnepaycd/QYBUser.git'
# Default branch is :master
# ask :branch, proc { `git rev-parse --abbrev-ref HEAD`.chomp }
# Default deploy_to directory is /var/www/my_app
# config in stage file
# 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, :info
# how many old releases do we want to keep, not much
set :keep_releases, 5
# 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}
SSHKit.config.command_map[:rake] = "bundle exec rake" #8
SSHKit.config.command_map[:rails] = "bundle exec rails"
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
after :finishing, 'deploy:cleanup'
end
目前无解中......求各位高手不吝解答