diff --git a/.gitignore b/.gitignore index b23c1cdea..aad805e24 100644 --- a/.gitignore +++ b/.gitignore @@ -4,49 +4,51 @@ # or operating system, you probably want to add a global ignore instead: # git config --global core.excludesfile ~/.gitignore_global +# Ignore .swp files +.*.swp + # Ignore bundler config /.bundle +# Ignore mac stuff +.DS_Store + +# Ignore Rubymine config +/.idea + +# Ignore .project files +/.project + +# Ignore .rbenv-vars +/.rbenv-vars + # Ignore database config /config/database.yml +# Ignore coverage stuff +/coverage + # Ignore the default SQLite database. /db/*.sqlite3 # Ignore local changes to schema.rb (e. g. through extentions) /db/schema.rb +# Ignore custom gem file +/Gemfile.local + +# Ignore node modules +/node_modules + # Ignore all logfiles and tempfiles. /log -/tmp/* -/tmp/pids/* /public/assets/*.* /public/assets/app /public/assets/custom +/tmp/* +/tmp/pids/* # except /tmp/pids/ which is needed for certain Zammad processes !/tmp !/tmp/pids !/tmp/pids/.keep - -# Ignore custom gem file -/Gemfile.local - -# Ignore .project files -/.project - -# Ignore local database settings -/config/database.yml - -# Ignore mac stuff -.DS_Store - -# Ignore .swp files -.*.swp - -# Ignore coverage stuff -/coverage - -# Ignore Rubymine config -/.idea -node_modules diff --git a/Gemfile b/Gemfile index 52624c5c0..b50c2e5a6 100644 --- a/Gemfile +++ b/Gemfile @@ -113,7 +113,9 @@ group :development, :test do gem 'github_changelog_generator' end -gem 'puma' +gem 'puma', group: :puma +gem 'unicorn', group: :unicorn + # load onw gem's local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local') diff --git a/Gemfile.lock b/Gemfile.lock index d2ffa73ec..fa86ca667 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -152,6 +152,7 @@ GEM inflection (1.0.0) json (1.8.3) jwt (1.5.4) + kgio (2.11.0) koala (2.4.0) addressable faraday @@ -271,6 +272,7 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rainbow (2.1.0) + raindrops (0.17.0) rake (11.2.2) rb-fsevent (0.9.7) rb-inotify (0.9.7) @@ -371,6 +373,9 @@ GEM unf_ext unf_ext (0.0.7.2) unicode-display_width (1.1.1) + unicorn (5.2.0) + kgio (~> 2.6) + raindrops (~> 0.7) websocket (1.2.3) writeexcel (1.0.5) zendesk_api (1.14.0) @@ -447,6 +452,7 @@ DEPENDENCIES therubyracer twitter uglifier + unicorn writeexcel zendesk_api diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 000000000..1f9f7107f --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,35 @@ +APP_DIR="." +UNICORN_DIR="#{APP_DIR}" +UNICORN_WORKER="4" +UNICORN_TIMEOUT="30" +RAILS_PID_DIR="#{APP_DIR}/tmp/pids" +RAILS_LOG_DIR="#{APP_DIR}/log" + +worker_processes UNICORN_WORKER.to_i +working_directory UNICORN_DIR +timeout UNICORN_TIMEOUT.to_i +pid "#{RAILS_PID_DIR}/unicorn.pid" +stderr_path "#{RAILS_LOG_DIR}/unicorn_error.log" +stdout_path "#{RAILS_LOG_DIR}/unicorn_access.log" + +before_fork do |server, worker| + ## + # When sent a USR2, Unicorn will suffix its pidfile with .oldbin and + # immediately start loading up a new version of itself (loaded with a new + # version of our app). When this new Unicorn is completely loaded + # it will begin spawning workers. The first worker spawned will check to + # see if an .oldbin pidfile exists. If so, this means we've just booted up + # a new Unicorn and need to tell the old one that it can now die. To do so + # we send it a QUIT. + # + # Using this method we get 0 downtime deploys. + + old_pid = "#{RAILS_PID_DIR}/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