web-dev-qa-db-fra.com

Comment utiliser le fichier de configuration de puma?

Je suivais ce guide il documente le fichier puma.rb qui est stocké dans le répertoire de configuration de l'application.

Le guide est un peu floconneux, mais voici ce que je suppose que le fichier puma.rb fait. Au lieu d'exécuter de telles commandes pour obtenir l'exécution de puma sur un socket spécifié:

bundle exec puma -e production -b unix:///var/run/my_app.sock

Vous pouvez simplement spécifier le port, le pid, la session et d'autres paramètres dans le fichier puma.rb comme ceci:

Rails_env = ENV['Rails_ENV'] || 'production'

threads 4,4

bind  "/home/starkers/Documents/alpha/tmp/socket"
pidfile "/home/starkers/Documents/alpha/tmp/pid"
state_path "/home/starkers/Documents/alpha/tmp/state"

activate_control_app

Et puis, vous pouvez cd dans la racine de l'application et exécuter une commande simple comme 

'puma' 

et les paramètres définis dans puma.rb seraient suivis. Malheureusement, cela ne semble pas fonctionner pour moi.

Au moins, j’ai exécuté puma à la racine d’une application test très petite, et aucun fichier .sock n’apparaissait dans /home/starkers/Documents/alpha/tmp/sockets alors cela signifie-t-il que cela ne fonctionne pas?

Comment puis-je obtenir ce travail? Je suis sur une machine de développement local, cela pourrait-il donc causer cette erreur? Y at-il un paramètre que je dois transmettre lors de l'exécution 

puma?

19
Starkers

J'étais également coincé pour essayer de trouver de la documentation sur le fichier de configuration de puma mais j'ai trouvé que le fichier le fichier config.ru tout-en-un était utile. Je l'ai formaté ici pour référence future:

# The directory to operate out of.
# The default is the current directory.

directory '/u/apps/lolcat'

# Load “path” as a rackup file.
# The default is “config.ru”.

rackup '/u/apps/lolcat/config.ru'

# Set the environment in which the rack's app will run. The value must be a string.
# The default is “development”.

environment 'production'

# Daemonize the server into the background. Highly suggest that
# this be combined with “pidfile” and “stdout_redirect”.
# The default is “false”.

daemonize
daemonize false

# Store the pid of the server in the file at “path”.

pidfile '/u/apps/lolcat/tmp/pids/puma.pid'

# Use “path” as the file to store the server info state. This is
# used by “pumactl” to query and control the server.

state_path '/u/apps/lolcat/tmp/pids/puma.state'

# Redirect STDOUT and STDERR to files specified. The 3rd parameter
# (“append”) specifies whether the output is appended, the default is
# “false”.

stdout_redirect '/u/apps/lolcat/log/stdout', '/u/apps/lolcat/log/stderr'
stdout_redirect '/u/apps/lolcat/log/stdout', '/u/apps/lolcat/log/stderr', true

# Disable request logging.
# The default is “false”.

quiet

# Configure “min” to be the minimum number of threads to use to answer
# requests and “max” the maximum.
# The default is “0, 16”.

threads 0, 16

# Bind the server to “url”. “tcp://”, “unix://” and “ssl://” are the only
# accepted protocols.
# The default is “tcp://0.0.0.0:9292”.

bind 'tcp://0.0.0.0:9292'
bind 'unix:///var/run/puma.sock'
bind 'unix:///var/run/puma.sock?umask=0777'
bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'

# Listens on port 7001
# The default is 9292
port 7001

# Instead of “bind 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'” you
# can also use the “ssl_bind” option.

 ssl_bind '127.0.0.1', '9292', { key: path_to_key, cert: path_to_cert }

# Code to run before doing a restart. This code should
# close log files, database connections, etc.

# This can be called multiple times to add code each time.

on_restart do
  puts 'On restart...'
end

# Command to use to restart puma. This should be just how to
# load puma itself (ie. 'Ruby -Ilib bin/puma'), not the arguments
# to puma, as those are the same as the original process.

restart_command '/u/app/lolcat/bin/restart_puma'

# === Cluster mode ===

# How many worker processes to run.
# The default is “0”.

workers 2

# Code to run when a worker boots to setup the process before booting
# the app.
# This can be called multiple times to add hooks.

on_worker_boot do
  puts 'On worker boot...'
end

# === Puma control rack application ===

# Start the puma control rack application on “url”. This application can
# be communicated with to control the main server. Additionally, you can
# provide an authentication token, so all requests to the control server
# will need to include that token as a query parameter. This allows for
# simple authentication.

# Check out https://github.com/puma/puma/blob/master/lib/puma/app/status.rb
# to see what the app has available.

activate_control_app 'unix:///var/run/pumactl.sock'
activate_control_app 'unix:///var/run/pumactl.sock', { auth_token: '12345' }
activate_control_app 'unix:///var/run/pumactl.sock', { no_token: true }

Ces paramètres sont ensuite placés dans un fichier Ruby (par exemple, config/puma.rb), puis, comme le dit Starkers, vous pouvez le lancer avec 

puma -Config/puma.rb

32
Richard Nienaber

Si un environnement est défini - ce qui est le cas dans votre exemple - le fichier de configuration est lu à partir de config/puma/[environment].rb et non pas config/puma.rb.

Il suffit de déplacer votre config/puma.rb à config/puma/production.rb et cela devrait fonctionner.

Lisez la documentation de Puma pour plus de détails: Fichier de configuration

6
Daniel Rikowski

Cela fonctionnera:

puma -C config/puma.rb
2
Starkers

Vous devez dire à puma où trouver votre fichier rackup, vous pouvez le faire en le mettant dans votre configuration:

rackup DefaultRackup

Il semble qu'un correctif pour cela soit fusionné dans master: https://github.com/puma/puma/pull/271

0
Schneems