Como posso iniciar o puma com um usuário / grupo especificado?

1

Estou usando o Rails 5 e o Puma 3 no CentOS. É possível (e como?) Especificar o usuário e o grupo sob o qual o puma é executado quando é iniciado? Eu preciso começar com o usuário / grupo apropriado para que o meu servidor nginx possa se conectar a ele e evitar o

2018/02/26 16:06:47 [crit] 11984#0: *1 connect() to unix:///home/rails/myproject/shared/sockets/puma.sock failed (13: Permission denied) while connecting to upstream, client: 50.244.40.27, server: server_ip, request: "GET / HTTP/1.1", upstream: "http://unix:///home/rails/myproject/shared/sockets/puma.sock:/", host: "server_ip"

erros que estou recebendo agora. Estou começando meu servidor puma assim

[rails@server myproject]$ puma -C config/puma.rb -e production -d

Abaixo está meu arquivo config / puma.rb

[rails@server myproject]$ cat config/puma.rb
# Puma can serve each request in a thread from an internal thread pool.
# The 'threads' method setting takes two numbers a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum, this matches the default thread size of Active Record.
#
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i
threads threads_count, threads_count

# Specifies the 'port' that Puma will listen on to receive requests, default is 3000.
#
port        ENV.fetch("PORT") { 3000 }

# Specifies the number of 'workers' to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# the concurrency of the application would be max 'threads' * 'workers'.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
workers ENV.fetch("WEB_CONCURRENCY") { 4 }

app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"

# Default to production
rails_env = ENV['RAILS_ENV'] || "production"
environment rails_env

# Set up socket location
bind "unix://#{shared_dir}/sockets/puma.sock"

# Logging
stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true

# Set master PID and state locations
pidfile "#{shared_dir}/pids/puma.pid"
state_path "#{shared_dir}/pids/puma.state"
activate_control_app

# Use the 'preload_app!' method when specifying a 'workers' number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory. If you use this option
# you need to make sure to reconnect any threads in the 'on_worker_boot'
# block.
#
# preload_app!

# The code in the 'on_worker_boot' will be called if you are using
# clustered mode by specifying a number of 'workers'. After each worker
# process is booted this block will be run, if you are using 'preload_app!'
# option you will want to use this block to reconnect to any threads
# or connections that may have been created at application boot, Ruby
# cannot share connections between processes.
#
on_worker_boot do
  require "active_record"
  ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
  ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
end

# Allow puma to be restarted by 'rails restart' command.
plugin :tmp_restart
    
por Dave 26.02.2018 / 22:16

0 respostas