Created
November 16, 2014 19:30
-
-
Save ik5/5dc72c4d7f68ca6ec364 to your computer and use it in GitHub Desktop.
general rack based server configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/path/to/log/file.log { | |
daily | |
compress | |
postrotate | |
kill -HUP `cat /path/to/app/tmp/puma/puma.pid` | |
endscript | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/puma.rb | |
#threads 0,32 # production | |
workers 2 | |
threads 0,16 | |
workers 0 | |
port 3000 | |
#daemonize # production | |
$app_path = File.expand_path(File.join(File.dirname(__FILE__), '..')) | |
tmp_dir = "#{$app_path}/tmp" | |
log_dir = "#{$app_path}/log" | |
tmp_puma = "#{tmp_dir}/puma" | |
dirs = [] | |
dirs << log_dir unless (File.directory? log_dir) | |
dirs << tmp_dir unless (File.directory? tmp_dir) | |
dirs << tmp_puma unless (File.directory? tmp_puma) | |
begin | |
require 'fileutils' | |
FileUtils::mkdir(dirs) if dirs.length > 0 | |
rescue | |
$stderr.puts 'Unable to create directories' | |
end | |
stdout_redirect 'log/stdout.log', 'log/stdout.log', true | |
pidfile 'tmp/puma/puma.pid' | |
state_path 'tmp/puma/puma.state' | |
prune_bundler | |
preload_app! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env puma | |
# The directory to operate out of. | |
# | |
# The default is the current directory. | |
# | |
# directory '/u/apps/lolcat' | |
# Use an object or block as the rack application. This allows the | |
# config file to be the application itself. | |
# | |
# app do |env| | |
# puts env | |
# | |
# body = 'Hello, World!' | |
# | |
# [200, { 'Content-Type' => 'text/plain', 'Content-Length' => body.length.to_s }, [body]] | |
# end | |
# 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' | |
# 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 | |
# Code to run when a worker boots to setup the process after booting | |
# the app. | |
# | |
# This can be called multiple times to add hooks. | |
# | |
# after_worker_boot do | |
# puts 'On worker boot...' | |
# end | |
# Allow workers to reload bundler context when master process is issued | |
# a USR1 signal. This allows proper reloading of gems while the master | |
# is preserved across a phased-restart. (incompatible with preload_app) | |
# (off by default) | |
# prune_bundler | |
# Preload the application before starting the workers; this conflicts with | |
# phased restart feature. (off by default) | |
# preload_app! | |
# Additional text to display in process listing | |
# | |
# tag 'app name' | |
# Change the default timeout of workers | |
# | |
# worker_timeout 60 | |
# === 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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Unicorn configuration | |
worker_processes 1 | |
#worker_processes 5 | |
$app_path = File.expand_path(File.join(File.dirname(__FILE__), '..')) | |
#puts $app_path | |
#working_directory $app_path | |
tmp_dir = "#{$app_path}/tmp" | |
log_dir = "#{$app_path}/log" | |
dirs = [] | |
dirs << log_dir unless (File.directory? log_dir) | |
dirs << tmp_dir unless (File.directory? tmp_dir) | |
begin | |
require 'fileutils' | |
FileUtils::mkdir(dirs) if dirs.length > 0 | |
rescue | |
$stderr.puts 'Unable to create directories' | |
end | |
pid "#{$app_path}/tmp/unicorn.pid" | |
listen 3000 | |
stderr_path "#{$app_path}/log/unicorn.stderr.log" | |
stdout_path "#{$app_path}/log/unicorn.stdout.log" | |
before_fork do |server, worker| | |
old_pid = "#{$app_path}/tmp/unicorn.pid.oldbin" | |
if File.exists?(old_pid) && server.pid != old_pid | |
begin | |
Process.kill("QUIT", File.read(old_pid).to_i) | |
rescue Errno::ENOENT, Errno::ESRCH | |
# someone else did our job for us | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[uwsgi] | |
http = 127.0.0.1:3000 | |
master = true | |
rack = config.ru | |
lazy-apps = true | |
processes = 4 | |
logto = log/uwsgi.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment