我正在尝试构建一个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,除了使用puma.rb文件中未定义的#{shared_path}
变量外,似乎没什么好奇的。 / p>
#!/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
我错过了什么吗?
答案 0 :(得分:1)
快速重新阅读您的问题后,问题立即显现出来。您正在设置需要使用单引号字符串进行插值的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"
...