Capistrano在部署到生产时不会创建puma pid

时间:2016-01-01 23:20:13

标签: ruby-on-rails capistrano

我有一个简单的rails应用程序,我尝试使用Capistrano部署到生产服务器,但在尝试创建puma.pid时似乎失败了。

当我检查puma.access.log时,我看到以下内容,

/home/capin/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/uri/rfc3986_parser.rb:66:in `split': bad URI(is not URI?): unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock (URI::InvalidURIError)
    from /home/capin/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/uri/rfc3986_parser.rb:72:in `parse'
    from /home/capin/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/uri/common.rb:226:in `parse'
    from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/binder.rb:85:in `block in parse'
    from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/binder.rb:84:in `each'
    from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/binder.rb:84:in `parse'
    from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/runner.rb:119:in `load_and_bind'
    from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/single.rb:79:in `run'
    from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/lib/puma/cli.rb:215:in `run'
    from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/gems/puma-2.15.3/bin/puma:10:in `<top (required)>'
    from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/bin/puma:23:in `load'
    from /home/capin/apps/Tshirt/shared/bundle/ruby/2.2.0/bin/puma:23:in `<main>'

有人知道为什么美洲狮会出现这个错误吗?如果需要,我可以发布更多配置文件。

运行deploy命令时的控制台输出

INFO [5680e746] Finished in 2.087 seconds with exit status 0 (successful).
DEBUG [d53f0457] Running /usr/bin/env if test ! -d /home/capin/apps/Tshirt/current; then echo "Directory does not exist '/home/capin/apps/Tshirt/current'" 1>&2; false; fi on youtee.io
DEBUG [d53f0457] Command: if test ! -d /home/capin/apps/Tshirt/current; then echo "Directory does not exist '/home/capin/apps/Tshirt/current'" 1>&2; false; fi
DEBUG [d53f0457] Finished in 0.296 seconds with exit status 0 (successful).
DEBUG [54524c04] Running /usr/bin/env [ -f /home/capin/apps/Tshirt/shared/tmp/pids/puma.pid ] on youtee.io
DEBUG [54524c04] Command: [ -f /home/capin/apps/Tshirt/shared/tmp/pids/puma.pid ]
DEBUG [54524c04] Finished in 0.310 seconds with exit status 1 (failed).
DEBUG [287a3b10] Running /usr/bin/env if test ! -d /home/capin/apps/Tshirt/releases; then echo "Directory does not exist '/home/capin/apps/Tshirt/releases'" 1>&2; false; fi on youtee.io
DEBUG [287a3b10] Command: if test ! -d /home/capin/apps/Tshirt/releases; then echo "Directory does not exist '/home/capin/apps/Tshirt/releases'" 1>&2; false; fi
DEBUG [287a3b10] Finished in 0.217 seconds with exit status 0 (successful).
INFO [5a813829] Running /usr/bin/env echo "Branch master (at 538f125) 
deployed as release 20160101233746 by capin" >> /home/capin/apps/Tshirt/revisions.log on youtee.io
DEBUG [5a813829] Command: echo "Branch master (at 538f125) deployed as release 20160101233746 by capin" >> /home/capin/apps/Tshirt/revisions.log
INFO [5a813829] Finished in 0.248 seconds with exit status 0 (successful).

production.rb

# server-based syntax
# ======================
# Defines a single server with a list of roles and multiple properties.
# You can define all roles on a single server, or split them:

# server 'example.com', user: 'deploy', roles: %w{app db web}, my_property: :my_value
# server 'example.com', user: 'deploy', roles: %w{app web}, other_property: :other_value
# server 'db.example.com', user: 'deploy', roles: %w{db}
server 'youtee.io', port: 4321, roles: [:web, :app, :db], primary: true

set :rvm_ruby_string, '2.2.1'
set :repo_url,        'git@bitbucket.org:ipatch/tshirt.git'
set :application,     'Tshirt'
set :user,            'capin'
set :puma_threads,    [4, 16]
set :puma_workers,    0

# Don't change these unless you know what you're doing
set :pty,             true
set :use_sudo,        false
set :stage,           :production
set :deploy_via,      :remote_cache
set :deploy_to,       "/home/#{fetch(:user)}/apps/#{fetch(:application)}"
# files we want symlinking to specific entries in shared.
set :linked_files,    %w{config/database.yml config/secrets.yml}
# see this SO answer, http://stackoverflow.com/a/32011351/708807
# set :linked_dirs, fetch(:linked_dirs, []).push('public/uploads')
set :puma_bind,       "tcp://0.0.0.0:9294" 
set :puma_bind,       "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"
set :puma_state,      "#{shared_path}/tmp/pids/puma.state"
set :puma_pid,        "#{shared_path}/tmp/pids/puma.pid"
set :puma_access_log, "#{release_path}/log/puma.error.log"
set :puma_error_log,  "#{release_path}/log/puma.access.log"
set :ssh_options,     { forward_agent: true, user: fetch(:user), keys: %w(~/.ssh/id_rsa.pub) }
set :puma_preload_app, true
set :puma_worker_timeout, nil
set :puma_init_active_record, true  # Change to false when not using ActiveRecord

namespace :puma do
  desc 'Create Directories for Puma Pids and Socket'
  task :make_dirs do
    on roles(:app) do
      execute "mkdir #{shared_path}/tmp/sockets -p"
      execute "mkdir #{shared_path}/tmp/pids -p"
    end
  end

    before :start, :make_dirs
end

namespace :deploy do
  desc "Make sure local git is in sync with remote."
  task :check_revision do
    on roles(:app) do
      # preserve uploaded files through Capistrano deployments
      # ln -n = ln -h, which if target dir is a sym link don't follow
      # ln -f, if already linked unlink so new link can be created
      # ln -s, creates a symlink
      # execute :ln, "-nfs #{shared_path}/public/uploads/store #{release_path}/public/uploads/store"
      unless `git rev-parse HEAD` == `git rev-parse origin/master`
        puts "WARNING: HEAD is not the same as origin/master"
        puts "Run `git push` to sync changes."
        exit
      end
    end
  end

  desc 'Initial Deploy'
  task :initial do
    on roles(:app) do
      before 'deploy:restart', 'puma:start'
      invoke 'deploy'
    end
  end

  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 5 do
      invoke 'puma:restart'
    end
  end

  before :starting,     :check_revision
  after  :finishing,    :compile_assets
  after  :finishing,    :cleanup
  after  :finishing,    :restart
end



# role-based syntax
# ==================

# Defines a role with one or multiple servers. The primary server in each
# group is considered to be the first unless any  hosts have the primary
# property set. Specify the username and a domain or IP for the server.
# Don't use `:all`, it's a meta role.

# role :app, %w{deploy@example.com}, my_property: :my_value
# role :web, %w{user1@primary.com user2@additional.com}, other_property: :other_value
# role :db,  %w{deploy@example.com}



# Configuration
# =============
# You can set any configuration variable like in config/deploy.rb
# These variables are then only loaded and set in this stage.
# For available Capistrano configuration variables see the documentation page.
# http://capistranorb.com/documentation/getting-started/configuration/
# Feel free to add new variables to customise your setup.



# Custom SSH Options
# ==================
# You may pass any option but keep in mind that net/ssh understands a
# limited set of options, consult the Net::SSH documentation.
# http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start
#
# Global options
# --------------

set :ssh_options, {
   keys: %w(/Users/capin/.ssh/id_rsa),
   forward_agent: true,
   auth_methods: %w(publickey password)
   # port: 4321,
  }

#  set :ssh_options, {
#    keys: %w(/home/rlisowski/.ssh/id_rsa),
#    forward_agent: false,
#    auth_methods: %w(password)
#  }
#
# The server-based syntax can be used to override options:
# ------------------------------------
# server 'example.com',
#   user: 'user_name',
#   roles: %w{web app},
#   ssh_options: {
#     user: 'user_name', # overrides user setting above
#     keys: %w(/home/user_name/.ssh/id_rsa),
#     forward_agent: false,
#     auth_methods: %w(publickey password)
#     # password: 'please use keys'
#   }

共享/ puma.rb

#!/usr/bin/env puma

directory '/home/capin/apps/Tshirt/current'
rackup "/home/capin/apps/Tshirt/current/config.ru"
environment 'production'

pidfile "/home/capin/apps/Tshirt/shared/tmp/pids/puma.pid"
state_path "/home/capin/apps/Tshirt/shared/tmp/pids/puma.state"
stdout_redirect '/home/capin/apps/Tshirt/current/log/puma.error.log', '/home/capin/apps/Tshirt/current/log/puma.access.log', true


threads 4,16

bind 'unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock'

workers 0



preload_app!


on_restart do
  puts 'Refreshing Gemfile'
  ENV["BUNDLE_GEMFILE"] = "/home/capin/apps/Tshirt/current/Gemfile"
end


on_worker_boot do
  ActiveSupport.on_load(:active_record) do
    ActiveRecord::Base.establish_connection
  end
end

1 个答案:

答案 0 :(得分:2)

在你的puma / capistrano配置文件中看起来像是错误。我认为您将行unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock放入单个配额而不是双精度,并且字符串插值不起作用:)

<强>更新 检查您的puma_bind值,应该是

set :puma_bind, "unix://#{shared_path}/tmp/sockets/#{fetch(:application)}-puma.sock"

双重配额