orats 0.8.1 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a725f12656a6becdd6ae20faf0c0bda7931155d
4
- data.tar.gz: 244645b83953ef5e8e86cd384fd3c1af29ff48ea
3
+ metadata.gz: 06d673cccc421756a9ce6a7398c8a5953245f7c7
4
+ data.tar.gz: 9bea9a885137b89ff186287604a54bec948ff159
5
5
  SHA512:
6
- metadata.gz: 22b712f9ff800cb0e0c38849972df8ef4ae3ed787e504a7a8962be3a726530e35bbf16ede4d65f08c6e0f15749f710e6a903de49e46ae0ec9b46b44c2a0bff44
7
- data.tar.gz: b25aa0727359cdba80242c209c21811232178ef0f12048924e5967f7397dc3e9b9e921338449541d3332c12dabdcde70d77c0d4f824fcce666e39f5f6b9a625b
6
+ metadata.gz: 0b6b7592f901be422559dca5b4409e9fd2db5ff579100d5e472d6d522a44cdcfc8e68614a1172ce046f3371385ad414b62a743e014ecdc9ec7691ea32a6bc55e
7
+ data.tar.gz: 52d2a71d2b084bb80a55e0f97531d3fe6d1738bad452d623452c900d74af8520d43f2f85c27d9a79e1dccee7c00893e46b734e49aa5ef02c21f001a9d1252c3e
data/README.md CHANGED
@@ -104,7 +104,7 @@ All of the changes have git commits to go with them. After generating a project
104
104
  - **Core changes**:
105
105
  - Use `postgres` as the primary SQL database
106
106
  - Use `redis` as the cache backend
107
- - Use `puma` as the web server
107
+ - Use `puma` or `unicorn` as the web backend
108
108
  - Use `sidekiq` as a background worker
109
109
  - **Features**:
110
110
  - Configure scheduled jobs and tasks using `whenever`
data/lib/orats/cli.rb CHANGED
@@ -50,6 +50,7 @@ module Orats
50
50
  option :template, default: '', aliases: '-t'
51
51
  option :custom, default: '', aliases: '-c'
52
52
  option :skip_server_start, type: :boolean, default: false, aliases: '-S'
53
+ option :backend, default: 'puma', aliases: '-b'
53
54
  option :rc, default: ''
54
55
  desc 'new PATH [options]', 'Create a new orats application'
55
56
  long_desc File.read(File.join(File.dirname(__FILE__), 'cli_help/new'))
@@ -24,4 +24,6 @@ Template features:
24
24
 
25
25
  Project features:
26
26
 
27
+ `--backend` to switch to a different server backend, ie. unicorn
28
+
27
29
  `--skip-server-start` to skip automatically running puma and sidekiq [false]
@@ -41,6 +41,7 @@ module Orats
41
41
  gsub_postgres_info
42
42
  gsub_redis_info
43
43
  gsub_readme
44
+ gsub_unicorn if @options[:backend] == 'unicorn'
44
45
 
45
46
  bundle_install
46
47
  bundle_binstubs
@@ -99,6 +100,17 @@ module Orats
99
100
  commit 'Update the readme'
100
101
  end
101
102
 
103
+ def gsub_unicorn
104
+ task 'Update files for switching to unicorn'
105
+
106
+ gsub_file "#{@target_path}/Procfile", 'puma -C config/puma.rb',
107
+ 'unicorn -c config/unicorn.rb'
108
+ gsub_file "#{@target_path}/Gemfile", "gem 'puma'", "#gem 'puma'"
109
+ gsub_file "#{@target_path}/Gemfile", "#gem 'unic", "gem 'unic"
110
+
111
+ commit 'Switch from puma to unicorn'
112
+ end
113
+
102
114
  def bundle_install
103
115
  task 'Run bundle install, this may take a while'
104
116
  run_from @target_path, 'bundle install'
@@ -108,7 +120,8 @@ module Orats
108
120
 
109
121
  def bundle_binstubs
110
122
  task 'Run bundle binstubs for a few gems'
111
- run_from @target_path, 'bundle binstubs whenever puma sidekiq'
123
+ run_from @target_path,
124
+ "bundle binstubs whenever #{@options[:backend]} sidekiq"
112
125
 
113
126
  commit 'Add binstubs for the important gems'
114
127
  end
@@ -38,7 +38,7 @@ module Orats
38
38
  task 'Check if the postgres database exists'
39
39
 
40
40
  # detect if the database already exists
41
- database = File.basename(@target_path)
41
+ database = "#{File.basename(@target_path)}_development"
42
42
  return if run("#{postgres_bin} -d #{database} -l | " + \
43
43
  "grep #{database} | wc -l", capture: true).chomp == '0'
44
44
 
@@ -195,9 +195,18 @@ def add_puma_config
195
195
  task __method__
196
196
 
197
197
  orats_to_local 'config/puma.rb'
198
+ gsub_file 'config/puma.rb', 'app_name', app_name
198
199
  commit 'Add the puma config'
199
200
  end
200
201
 
202
+ def add_unicorn_config
203
+ task __method__
204
+
205
+ orats_to_local 'config/unicorn.rb'
206
+ gsub_file 'config/unicorn.rb', 'app_name', app_name
207
+ commit 'Add the unicorn config'
208
+ end
209
+
201
210
  def add_sidekiq_config
202
211
  task __method__
203
212
 
@@ -494,6 +503,7 @@ update_app_secrets
494
503
  update_app_config
495
504
  update_database_config
496
505
  add_puma_config
506
+ add_unicorn_config
497
507
  add_sidekiq_config
498
508
  add_sitemap_config
499
509
  add_whenever_config
@@ -29,8 +29,24 @@ ACTION_MAILER_DEFAULT_TO: 'me@app_name.com'
29
29
  DATABASE_URL: 'postgresql://db_user@db_location:db_port/app_name?encoding=utf8&pool=5&timeout=5000'
30
30
  CACHE_URL: 'redis://cache_location:cache_port/0'
31
31
 
32
- PUMA_THREADS_MIN: 0
33
- PUMA_THREADS_MAX: 1
34
- PUMA_WORKERS: 0
35
-
32
+ # try setting these to 0/16 in production and tweak from there
33
+ # in development mode you should use 0/1 ( multi-threaded + debugging = :< )
34
+ # these only apply if you're using puma
35
+ THREADS_MIN: 0
36
+ THREADS_MAX: 1
37
+
38
+ # this should equal the number of CPU cores in production
39
+ # in development mode it set to 0 so puma does not go into cluster mode, unicorn
40
+ # will also correctly function with 0 workers in development mode
41
+ WORKERS: 1
42
+
43
+ # this should equal the database pool size
36
44
  SIDEKIQ_CONCURRENCY: 5
45
+
46
+ # the path where logs get written to
47
+ # in production you might consider /var/log/app_name
48
+ LOG_PATH: 'log'
49
+
50
+ # the path that will contain pids and sockets
51
+ # in production you will likely want to set this to '/var/run/app_name'
52
+ RUN_STATE_PATH: 'tmp'
@@ -13,6 +13,7 @@ gem 'pg', '~> 0.17.1'
13
13
  gem 'redis-rails', '~> 4.0.0'
14
14
 
15
15
  gem 'puma', '~> 2.9.0'
16
+ #gem 'unicorn', '~> 4.8.3'
16
17
  gem 'sidekiq', '~> 3.2.1'
17
18
  gem 'sinatra', '>= 1.4.5', require: false
18
19
 
@@ -1,3 +1,3 @@
1
- web: puma -C config/puma.rb -p 3000 | grep -v --line-buffered ' 304 -'
1
+ web: puma -C config/puma.rb | grep -v --line-buffered ' 304 -'
2
2
  worker: sidekiq -C config/sidekiq.yml
3
3
  log: tail -f log/development.log | grep -xv --line-buffered '^[[:space:]]*' | grep -v --line-buffered '/assets/'
@@ -1,19 +1,29 @@
1
1
  environment ENV['RAILS_ENV']
2
2
 
3
- threads ENV['PUMA_THREADS_MIN'].to_i, ENV['PUMA_THREADS_MAX'].to_i
4
- workers ENV['PUMA_WORKERS'].to_i
3
+ threads ENV['THREADS_MIN'].to_i, ENV['THREADS_MAX'].to_i
4
+ workers ENV['WORKERS'].to_i
5
5
 
6
- pidfile "tmp/puma.pid"
6
+ if ENV['RAILS_ENV'] == 'development' || ENV['RAILS_ENV'] == 'test'
7
+ bind 'tcp://0.0.0.0:3000'
8
+ else
9
+ bind "unix:#{ENV['RUN_STATE_PATH']}/app_name"
10
+ end
11
+
12
+ pidfile "#{ENV['RUN_STATE_PATH']}/app_name.pid"
13
+
14
+ worker_timeout 30
15
+
16
+ stdout_redirect "#{ENV['LOG_PATH']}/app_name.stdout.log",
17
+ "#{ENV['LOG_PATH']}/app_name.stderr.log"
7
18
 
8
- # https://github.com/puma/puma/blob/master/examples/config.rb#L125
9
- prune_bundler
19
+ preload_app!
10
20
 
11
- restart_command 'bundle exec bin/puma'
21
+ restart_command 'bundle exec puma'
12
22
 
13
23
  on_worker_boot do
14
- require 'active_record'
24
+ defined?(ActiveRecord::Base) and
25
+ ActiveRecord::Base.connection.disconnect!
15
26
 
16
- config_path = File.expand_path('../database.yml', __FILE__)
17
- ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
18
- ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'] || YAML.load_file(config_path)[ENV['RAILS_ENV']])
27
+ defined?(ActiveRecord::Base) and
28
+ ActiveRecord::Base.establish_connection
19
29
  end
@@ -1,5 +1,5 @@
1
1
  ---
2
- :pidfile: 'tmp/sidekiq.pid'
2
+ :pidfile: "<%= ENV['RUN_STATE_PATH'] %>/sidekiq.pid"
3
3
  :concurrency: <%= ENV['SIDEKIQ_CONCURRENCY'].to_i %>
4
4
  :queues:
5
5
  - default
@@ -0,0 +1,52 @@
1
+ # heavily inspired by gitlab:
2
+ # https://github.com/gitlabhq/gitlabhq/blob/master/config/unicorn.rb.example
3
+
4
+ worker_processes ENV['WORKERS'].to_i
5
+
6
+ if ENV['RAILS_ENV'] == 'development' || ENV['RAILS_ENV'] == 'test'
7
+ listen '0.0.0.0:3000'
8
+ else
9
+ listen "unix:#{ENV['RUN_STATE_PATH']}/app_name", backlog: 64
10
+ end
11
+
12
+ pid "#{ENV['RUN_STATE_PATH']}/app_name.pid"
13
+
14
+ timeout 30
15
+
16
+ stdout_path "#{ENV['LOG_PATH']}/app_name.stdout.log"
17
+ stderr_path "#{ENV['LOG_PATH']}/app_name.stderr.log"
18
+
19
+ preload_app true
20
+
21
+ GC.respond_to?(:copy_on_write_friendly=) and
22
+ GC.copy_on_write_friendly = true
23
+
24
+ check_client_connection false
25
+
26
+ before_fork do |server, worker|
27
+ defined?(ActiveRecord::Base) and
28
+ ActiveRecord::Base.connection.disconnect!
29
+
30
+ # The following is only recommended for memory/DB-constrained
31
+ # installations. It is not needed if your system can house
32
+ # twice as many worker_processes as you have configured.
33
+ #
34
+ # This allows a new master process to incrementally
35
+ # phase out the old master process with SIGTTOU to avoid a
36
+ # thundering herd (especially in the "preload_app false" case)
37
+ # when doing a transparent upgrade. The last worker spawned
38
+ # will then kill off the old master process with a SIGQUIT.
39
+ old_pid = "#{server.config[:pid]}.oldbin"
40
+ if old_pid != server.pid
41
+ begin
42
+ sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
43
+ Process.kill(sig, File.read(old_pid).to_i)
44
+ rescue Errno::ENOENT, Errno::ESRCH
45
+ end
46
+ end
47
+ end
48
+
49
+ after_fork do |server, worker|
50
+ defined?(ActiveRecord::Base) and
51
+ ActiveRecord::Base.establish_connection
52
+ end
data/lib/orats/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # set the version of this gem
2
2
  module Orats
3
- VERSION = '0.8.1'
3
+ VERSION = '0.9.0'
4
4
  end
@@ -23,6 +23,10 @@ class TestCLI < Minitest::Test
23
23
  assert_new '--template auth'
24
24
  end
25
25
 
26
+ def test_new_with_unicorn
27
+ assert_new '--backend unicorn'
28
+ end
29
+
26
30
  def test_new_with_invalid_template
27
31
  @target_path = generate_app_name
28
32
  @extra_flags = "#{ORATS_NEW_FLAGS} --template foo"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Janetakis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-30 00:00:00.000000000 Z
11
+ date: 2014-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -137,6 +137,7 @@ files:
137
137
  - lib/orats/templates/includes/new/rails/config/secrets.yml
138
138
  - lib/orats/templates/includes/new/rails/config/sidekiq.yml
139
139
  - lib/orats/templates/includes/new/rails/config/sitemap.rb
140
+ - lib/orats/templates/includes/new/rails/config/unicorn.rb
140
141
  - lib/orats/templates/includes/new/rails/lib/tasks/orats/favicon.rake
141
142
  - lib/orats/templates/includes/new/rails/public/404.html
142
143
  - lib/orats/templates/includes/new/rails/public/422.html