由于 "shared_path",Capistrano Puma 无法启动
Capistrano Puma won't start due to "shared_path"
我正在尝试构建一个 Capistrano 部署脚本,目前它可以正常工作,除了 Puma 部分:
set :puma_bind, 'unix://#{shared_path}/tmp/sockets/puma_myapp.sock;'
set :puma_state, '#{shared_path}/tmp/pids/puma_myapp.state'
set :puma_pid, '#{shared_path}/tmp/pids/puma_myapp.pid'
set :puma_access_log, '#{release_path}/log/puma.error.log'
set :puma_error_log, '#{release_path}/log/puma.access.log'
set :puma_conf, "#{shared_path}/puma.rb"
set :puma_threads, [4, 16]
set :puma_workers, 3
set :puma_env, 'production'
set :assets_roles, [:web, :app]
set :rails_assets_groups, :assets
set :keep_assets, 2
append :rbenv_map_bins, 'puma', 'pumactl'
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
当我执行脚本时,它在命令 puma:start
后失败并给出错误:
bundler: failed to load command: puma (/var/www/myapp/shared/bundle/ruby/2.5.0/bin/puma)
01 NameError: undefined local variable or method `shared_path' for #<Puma::DSL:0x000055e752c4c018>
01 Did you mean? state_path
我查看了上传到服务器的 shared/puma.rb conf,似乎没有什么奇怪的,除了 #{shared_path}
变量的使用,它没有在 puma.rb 文件:
#!/usr/bin/env puma
directory '/var/www/myapp/current'
rackup "/var/www/myapp/current/config.ru"
environment 'production'
tag ''
pidfile "#{shared_path}/tmp/pids/puma.pid"
state_path "#{shared_path}/tmp/pids/puma.state"
stdout_redirect '#{release_path}/log/puma.error.log', '#{release_path}/log/puma.access.log', true
threads 0,16
bind 'unix://#{shared_path}/tmp/sockets/puma_myapp.sock;'
workers 0
prune_bundler
on_restart do
puts 'Refreshing Gemfile'
ENV["BUNDLE_GEMFILE"] = ""
end
我是不是漏掉了什么?
快速重读您的问题后,问题立即变得显而易见。您正在设置需要用单引号字符串插值的 puma 设置,这会禁用插值 - 任何包含 #{...}
的设置都需要用双引号
括起来
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma_myapp.sock;"
set :puma_state, "#{shared_path}/tmp/pids/puma_myapp.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma_myapp.pid"
...
我正在尝试构建一个 Capistrano 部署脚本,目前它可以正常工作,除了 Puma 部分:
set :puma_bind, 'unix://#{shared_path}/tmp/sockets/puma_myapp.sock;'
set :puma_state, '#{shared_path}/tmp/pids/puma_myapp.state'
set :puma_pid, '#{shared_path}/tmp/pids/puma_myapp.pid'
set :puma_access_log, '#{release_path}/log/puma.error.log'
set :puma_error_log, '#{release_path}/log/puma.access.log'
set :puma_conf, "#{shared_path}/puma.rb"
set :puma_threads, [4, 16]
set :puma_workers, 3
set :puma_env, 'production'
set :assets_roles, [:web, :app]
set :rails_assets_groups, :assets
set :keep_assets, 2
append :rbenv_map_bins, 'puma', 'pumactl'
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
当我执行脚本时,它在命令 puma:start
后失败并给出错误:
bundler: failed to load command: puma (/var/www/myapp/shared/bundle/ruby/2.5.0/bin/puma)
01 NameError: undefined local variable or method `shared_path' for #<Puma::DSL:0x000055e752c4c018>
01 Did you mean? state_path
我查看了上传到服务器的 shared/puma.rb conf,似乎没有什么奇怪的,除了 #{shared_path}
变量的使用,它没有在 puma.rb 文件:
#!/usr/bin/env puma
directory '/var/www/myapp/current'
rackup "/var/www/myapp/current/config.ru"
environment 'production'
tag ''
pidfile "#{shared_path}/tmp/pids/puma.pid"
state_path "#{shared_path}/tmp/pids/puma.state"
stdout_redirect '#{release_path}/log/puma.error.log', '#{release_path}/log/puma.access.log', true
threads 0,16
bind 'unix://#{shared_path}/tmp/sockets/puma_myapp.sock;'
workers 0
prune_bundler
on_restart do
puts 'Refreshing Gemfile'
ENV["BUNDLE_GEMFILE"] = ""
end
我是不是漏掉了什么?
快速重读您的问题后,问题立即变得显而易见。您正在设置需要用单引号字符串插值的 puma 设置,这会禁用插值 - 任何包含 #{...}
的设置都需要用双引号
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma_myapp.sock;"
set :puma_state, "#{shared_path}/tmp/pids/puma_myapp.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma_myapp.pid"
...