Hipjea
Hipjea

Reputation: 401

Capistrano Puma won't start due to "shared_path"

I'm trying to build a Capistrano deployment script and it works so far except the Puma part :

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

When I execute the script, it fails after the command puma:start giving the errors :

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

I looked a the shared/puma.rb conf that is uploaded to the server, and nothing seems curious, except the use of the #{shared_path} variable, that isn't defined in the puma.rb file :

#!/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

Am I missing something ?

Upvotes: 0

Views: 843

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49910

After a quick reread of your question the issue immediately became apparent. You're setting your puma settings that need to be interpolated with single quote strings, which disables interpolations - Any of the settings that include #{...} need to be surrounded with double quotes

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"
...

Upvotes: 1

Related Questions