diff options
author | rhenium <rhenium@rhe.jp> | 2015-04-05 17:31:42 +0900 |
---|---|---|
committer | rhenium <rhenium@rhe.jp> | 2015-04-05 17:31:42 +0900 |
commit | a0b2cdaf4b6536a233b6339cf9a262cf800ff49b (patch) | |
tree | 0344b1c9d159f394f4b0a74a9be000fa931f56c2 | |
parent | 6b269ecd015a8162b879813fc5fb0cda205b9488 (diff) | |
parent | 609246084e9139b5cd7c68da22ceeba76ddb2cb0 (diff) | |
download | aclog-a0b2cdaf4b6536a233b6339cf9a262cf800ff49b.tar.gz |
Merge branch 'master' into vuejs
-rw-r--r-- | Gemfile | 4 | ||||
-rw-r--r-- | Gemfile.lock | 20 | ||||
-rw-r--r-- | config.ru | 11 | ||||
-rw-r--r-- | config/initializers/oink.rb | 3 | ||||
-rw-r--r-- | config/puma.rb | 22 | ||||
-rw-r--r-- | config/unicorn.rb | 36 | ||||
-rw-r--r-- | example/nginx.conf | 6 | ||||
-rw-r--r-- | lib/tasks/web.rake | 30 |
8 files changed, 53 insertions, 79 deletions
@@ -16,8 +16,7 @@ gem "jquery-rails" gem "bootstrap-sass" gem "turbolinks" -gem "unicorn" -gem "unicorn-worker-killer" +gem "puma" gem "dalli" gem "omniauth-twitter" @@ -34,6 +33,7 @@ group :development, :test do gem "web-console", "~> 2.0.0" gem "spring" gem "quiet_assets" + gem "oink" end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index c7255ad..86c4ed2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -100,7 +100,6 @@ GEM multipart-post (>= 1.2, < 3) ffi (1.9.8) formatador (0.2.5) - get_process_mem (0.2.0) globalid (0.3.3) activesupport (>= 4.1.0) grape (0.9.0) @@ -143,6 +142,7 @@ GEM hashie (3.4.1) hike (1.2.3) hitimes (1.2.2) + hodel_3000_compliant_logger (0.1.1) html2haml (2.0.0) erubis (~> 2.7.0) haml (~> 4.0.0) @@ -163,7 +163,6 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.2) - kgio (2.9.3) listen (2.10.0) celluloid (~> 0.16.0) rb-fsevent (>= 0.9.3) @@ -196,6 +195,9 @@ GEM nenv (~> 0.1) shellany (~> 0.0) oauth (0.4.7) + oink (0.10.1) + activerecord + hodel_3000_compliant_logger omniauth (1.2.2) hashie (>= 1.2, < 4) rack (~> 1.0) @@ -211,6 +213,8 @@ GEM slop (~> 3.4) pry-rails (0.3.4) pry (>= 0.9.10) + puma (2.11.1) + rack (>= 1.1, < 2.0) quiet_assets (1.1.0) railties (>= 3.1, < 5.0) rabl (0.11.6) @@ -246,7 +250,6 @@ GEM activesupport (= 4.2.1) rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) - raindrops (0.13.0) rake (10.4.2) rb-fsevent (0.9.4) rb-inotify (0.9.5) @@ -345,13 +348,6 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.6) - unicorn (4.8.3) - kgio (~> 2.6) - rack - raindrops (~> 0.7) - unicorn-worker-killer (0.4.3) - get_process_mem (~> 0) - unicorn (~> 4) virtus (1.0.5) axiom-types (~> 0.1) coercible (~> 1.0) @@ -388,8 +384,10 @@ DEPENDENCIES msgpack msgpack-rpc mysql2 + oink omniauth-twitter pry-rails + puma quiet_assets rails (~> 4.2.0) rspec @@ -405,8 +403,6 @@ DEPENDENCIES twitter-text tzinfo-data uglifier - unicorn - unicorn-worker-killer web-console (~> 2.0.0) webmock yajl-ruby @@ -1,15 +1,4 @@ # This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) -if Rails.env.production? - # Unicorn self-process killer - require "unicorn/worker_killer" - - # Max requests per worker - use Unicorn::WorkerKiller::MaxRequests, 3072, 4096 - - # Max memory size (RSS) per worker - use Unicorn::WorkerKiller::Oom, (192*(1024**2)), (256*(1024**2)) -end - run Rails.application diff --git a/config/initializers/oink.rb b/config/initializers/oink.rb new file mode 100644 index 0000000..5bc53da --- /dev/null +++ b/config/initializers/oink.rb @@ -0,0 +1,3 @@ +if Rails.env.development? + Rails.application.middleware.use(Oink::Middleware, logger: Rails.logger) +end diff --git a/config/puma.rb b/config/puma.rb new file mode 100644 index 0000000..fa22c6b --- /dev/null +++ b/config/puma.rb @@ -0,0 +1,22 @@ +_rails_root = File.expand_path("../../", __FILE__) + +directory _rails_root + +_log_file = File.join(_rails_root, "log", "puma.log") +stdout_redirect _log_file, _log_file, true + +pidfile File.join(_rails_root, "tmp", "pids", "puma.pid") + +threads 4, 16 +workers 2 + +bind "unix://" + File.join(_rails_root, "tmp", "sockets", "puma.sock") +port 3000 + +on_worker_boot do + ActiveSupport.on_load(:active_record) do + ActiveRecord::Base.establish_connection + end +end + +preload_app! diff --git a/config/unicorn.rb b/config/unicorn.rb deleted file mode 100644 index fc20b0b..0000000 --- a/config/unicorn.rb +++ /dev/null @@ -1,36 +0,0 @@ -_rails_root = File.expand_path("../../", __FILE__) - -worker_processes 8 -working_directory _rails_root - -pid File.join(_rails_root, "tmp", "pids", "unicorn.pid").to_s - -listen File.join(_rails_root, "tmp", "sockets", "unicorn.sock"), backlog: 64 -listen 8080 - -_log_file = File.join(_rails_root, "log", "unicorn.log") -stderr_path _log_file -stdout_path _log_file - -preload_app true -GC.respond_to?(:copy_on_write_friendly=) and - GC.copy_on_write_friendly = true - -before_fork do |server, worker| - defined?(ActiveRecord::Base) and - ActiveRecord::Base.connection.disconnect! - - old_pid = "#{server.config[:pid]}.oldbin" - if old_pid != server.pid - begin - sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU - Process.kill(sig, File.read(old_pid).to_i) - rescue Errno::ENOENT, Errno::ESRCH - end - end -end - -after_fork do |server, worker| - defined?(ActiveRecord::Base) and - ActiveRecord::Base.establish_connection -end diff --git a/example/nginx.conf b/example/nginx.conf index d854e66..298f0a6 100644 --- a/example/nginx.conf +++ b/example/nginx.conf @@ -31,7 +31,7 @@ http { #gzip on; upstream aclog-webserver { - server unix:/var/webapps/aclog/tmp/sockets/unicorn.sock; + server unix:/var/webapps/aclog/tmp/sockets/puma.sock; } server { @@ -40,10 +40,10 @@ http { location / { root /var/webapps/aclog/public; - try_files $uri $uri/index.xhtml $uri.xhtml @unicorn; + try_files $uri $uri/index.xhtml $uri.xhtml @rack; } - location @unicorn { + location @rack { proxy_redirect off; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; diff --git a/lib/tasks/web.rake b/lib/tasks/web.rake index 302e57c..c75868b 100644 --- a/lib/tasks/web.rake +++ b/lib/tasks/web.rake @@ -1,5 +1,5 @@ namespace :web do - @web_pid_file = Rails.root.join("tmp", "pids", "unicorn.pid").to_s + @web_pid_file = Rails.root.join("tmp", "pids", "puma.pid").to_s def web_read_pid Integer(File.read(@web_pid_file)) rescue nil @@ -9,53 +9,53 @@ namespace :web do Process.kill(0, pid) rescue false end - desc "Start aclog collector (master) in the foreground" + desc "Start web server in the foreground" task :run do - system "unicorn -E #{Rails.env} -c #{Rails.root}/config/unicorn.rb" + system "puma -e #{Rails.env} -C #{Rails.root}/config/puma.rb" end - desc "Start web server (Unicorn)" + desc "Start web server" task :start do pid = web_read_pid if pid && process_alive?(pid) - STDERR.puts "Unicorn is already started (PID: #{pid})" + STDERR.puts "Web server is already started (PID: #{pid})" next end - system "unicorn -D -E #{Rails.env} -c #{Rails.root}/config/unicorn.rb" + system "puma -d -e #{Rails.env} -C #{Rails.root}/config/puma.rb" end - desc "Stop web server (Unicorn)" + desc "Stop web server" task :stop do pid = web_read_pid unless process_alive?(pid) - STDERR.puts "Unicorn is not running." + STDERR.puts "Puma is not running." next end - Process.kill(:QUIT, pid) + Process.kill(:TERM, pid) while process_alive?(pid) - sleep 0.1 + sleep 0.05 end end - desc "Retart web server (Unicorn)" + desc "Retart web server" task :restart do pid = web_read_pid unless process_alive?(pid) - STDERR.puts "Unicorn is not running." + STDERR.puts "Puma is not running." Rake::Task["web:start"].invoke end Process.kill("USR2", pid) end - desc "Show status of web server (Unicorn)" + desc "Show status of web server" task :status do pid = web_read_pid if pid && process_alive?(pid) - STDOUT.puts "Unicorn is running." + STDOUT.puts "Puma is running." else - STDOUT.puts "Unicorn is not running." + STDOUT.puts "Puma is not running." end end end |