negroku 2.0.0.pre5 → 2.0.0.pre6

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: 28e09328759e8f4a35e94983b195187e2547946a
4
- data.tar.gz: a86bcabcd3e51363784be9648ffc2b080fd3f571
3
+ metadata.gz: 8a50e3178dc8ccdc1dce8f8ce983dfba19eeade5
4
+ data.tar.gz: d5f480fb58ac84a329522c32ee04e7c66204e17f
5
5
  SHA512:
6
- metadata.gz: 4bb0ce55d5b4ea0003ee17d6d1e29431f1014350f882a2a589965e0ba62d93c5f5d085669ff97a9b551e16de1b920b3f07741effc9bda55799afbcada1e6486c
7
- data.tar.gz: 08227f2fb7e063b7f9622dd76473ae056c93952a66f6d801ab70364659c645fa30e8cecfc27284fe2ee5cc92be2b315e4a4d30de5489bf5e835e97ff9baaf221
6
+ metadata.gz: 014869c6a9f70ab69e226c9b041e5ab6503897c1cc80f414e0e4630bb0b0e5488b41ea0d8458250f98b7102d69b11d5725a4e93b6b06e335a43280acc4322809
7
+ data.tar.gz: 2ef7920ec67bc35ed978653a133e6819c160e8eeded18e5014a123ff016db90347b689078908fd9e2d9f8e4e7bddec12b1aed51c8b212375b5f488ba812b7336
@@ -20,14 +20,13 @@ end
20
20
 
21
21
  # Load Negroku tasks
22
22
  load_task "negroku"
23
- load_task "rbenv" if was_required? 'capistrano/rbenv'
24
- load_task "nodenv" if was_required? 'capistrano/nodenv'
25
- load_task "bower" if was_required? 'capistrano/bower'
26
- load_task "bundler" if was_required? 'capistrano/bundler'
27
- load_task "rails" if was_required? 'capistrano/rails'
28
- load_task "nginx" if was_required? 'capistrano/nginx'
29
- load_task "unicorn" if was_required? 'capistrano3/unicorn'
30
- load_task "delayed_job" if was_required? 'capistrano/delayed-job'
31
- load_task "whenever" if was_required? 'whenever/capistrano'
32
-
23
+ load_task "rbenv" if required? 'capistrano/rbenv'
24
+ load_task "nodenv" if required? 'capistrano/nodenv'
25
+ load_task "bower" if required? 'capistrano/bower'
26
+ load_task "bundler" if required? 'capistrano/bundler'
27
+ load_task "rails" if required? 'capistrano/rails'
28
+ load_task "nginx" if required? 'capistrano/nginx'
29
+ load_task "unicorn" if required? 'capistrano3/unicorn'
30
+ load_task "delayed_job" if required? 'capistrano/delayed-job'
31
+ load_task "whenever" if required? 'whenever/capistrano'
33
32
  load_task "log"
@@ -0,0 +1 @@
1
+ load_task 'eye/delayed_job', ['capistrano/delayed-job']
@@ -0,0 +1,2 @@
1
+ load_task 'eye/unicorn', ['capistrano3/unicorn']
2
+
@@ -0,0 +1,3 @@
1
+ require 'negroku/helpers'
2
+
3
+ load_task "eye"
@@ -2,6 +2,7 @@ require "erb"
2
2
 
3
3
  # Build the template
4
4
  def build_template(template, destination, binding)
5
+
5
6
  template_file = get_template_file(template)
6
7
 
7
8
  result = ERB.new(template_file, nil, '-').result(binding)
@@ -0,0 +1,9 @@
1
+ def watch_process(name, template = "tasks/eye/_#{name}.erb")
2
+ processes = fetch(:eye_watched_processes, {})
3
+
4
+ processes[name] = {
5
+ template: template
6
+ }
7
+
8
+ set :eye_watched_processes, processes
9
+ end
@@ -1,13 +1,26 @@
1
1
  require 'negroku/helpers/templates'
2
+ require 'negroku/helpers/watch'
2
3
  require 'negroku/helpers/logs'
3
4
  require 'negroku/helpers/env'
4
5
 
5
6
  # Find out if a specific library file was already required
6
- def was_required?(file)
7
+ def required?(file)
7
8
  rex = Regexp.new("/#{Regexp.quote(file)}\.(so|o|sl|rb)?")
8
9
  $LOADED_FEATURES.find { |f| f =~ rex }
9
10
  end
10
11
 
11
- def load_task(name)
12
- load File.join(File.dirname(__FILE__), 'tasks', "#{name}.rake")
12
+ def any_required?(arr)
13
+ arr.any? { |file| required?(file) }
14
+ end
15
+
16
+ def all_required?(arr)
17
+ arr.all? { |file| required?(file) }
18
+ end
19
+
20
+ def load_task(name, dependencies = [])
21
+ if all_required? dependencies
22
+ load File.join(File.dirname(__FILE__), 'tasks', "#{name}.rake")
23
+ else
24
+ fail "To load #{name} you need to include #{dependencies.join ", "}"
25
+ end
13
26
  end
@@ -0,0 +1,21 @@
1
+ #########
2
+ ## Adds support to monitor delayed_job processes through eye
3
+ #########
4
+
5
+ # Watch the delayed_job processes using the build in template
6
+ watch_process(:delayed_job);
7
+
8
+ # Override start, restart and stop delayed_job tasks to so they call
9
+ # the eye equivalents
10
+ # namespace :unicorn do
11
+ # ['start','restart','stop'].each do |cmd|
12
+ # if Rake::Task.task_defined?("unicorn:#{cmd}")
13
+ # Rake::Task["unicorn:#{cmd}"].clear_actions
14
+ # # Reload or restart unicorn after the application is published
15
+ # desc "#{cmd} unicorn through eye"
16
+ # task cmd do
17
+ # invoke "eye:#{cmd}", 'unicorn'
18
+ # end
19
+ # end
20
+ # end
21
+ # end
@@ -0,0 +1,21 @@
1
+ #########
2
+ ## Adds support to monitor unicorn processes through eye
3
+ #########
4
+
5
+ # Watch the unicorn processes using the build in template
6
+ watch_process(:unicorn);
7
+
8
+ # Override start, restart and stop unicorn tasks to so they call
9
+ # the eye equivalents
10
+ namespace :unicorn do
11
+ ['start','restart','stop'].each do |cmd|
12
+ if Rake::Task.task_defined?("unicorn:#{cmd}")
13
+ Rake::Task["unicorn:#{cmd}"].clear_actions
14
+ # Reload or restart unicorn after the application is published
15
+ desc "using eye"
16
+ task cmd do
17
+ invoke "eye:#{cmd}", 'unicorn'
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,87 @@
1
+ require 'negroku/helpers/templates'
2
+
3
+ ## eye.rb
4
+ #
5
+ # Adds eye variables and tasks
6
+
7
+ namespace :load do
8
+ task :defaults do
9
+ ###################################
10
+ ## eye template variables
11
+
12
+ # Local path to look for custom config template
13
+ set :eye_application_template, -> { "config/deploy/#{fetch(:stage)}/eye.rb.erb" }
14
+ end
15
+ end
16
+
17
+
18
+ namespace :eye do
19
+
20
+ desc "Loads eye config and starts monitoring"
21
+ task :load do
22
+ on release_roles fetch(:eye_roles) do
23
+ within "#{current_path}" do
24
+ execute :eye, :load, "#{shared_path}/config/eye.rb"
25
+ end
26
+ end
27
+ end
28
+
29
+ [:start,:restart, :info, :stop].each do |cmd|
30
+ # Single process
31
+ desc "Calls eye's #{cmd.to_s} on a process"
32
+ task "#{cmd}:process", [:name] do |t, args|
33
+ on release_roles fetch(:eye_roles) do
34
+ within "#{current_path}" do
35
+ execute :eye, cmd, "#{args[:name]}"
36
+ end
37
+ end
38
+ end
39
+ #
40
+ desc "Calls eye's #{cmd.to_s} on the whole app"
41
+ task cmd do |t, args|
42
+ on release_roles fetch(:eye_roles) do
43
+ within "#{current_path}" do
44
+ execute :eye, cmd, "#{fetch(:application)}"
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ # Adds some task on complement the capistrano3-unicorn tasks
52
+ # This tasks are under the negroku namespace for easier identification
53
+ namespace :negroku do
54
+
55
+ namespace :eye do
56
+
57
+ desc "Upload eye configuration file"
58
+ task :setup do
59
+ on release_roles fetch(:eye_roles) do
60
+ within "#{shared_path}/config" do
61
+ processes = fetch(:eye_watched_processes, {})
62
+
63
+ template_path = fetch(:eye_application_template)
64
+
65
+ # use a build in template if the template doesn't exists in the project
66
+ unless File.exists?(template_path)
67
+ template_path = "tasks/eye/application.eye.erb"
68
+ end
69
+
70
+ config = build_template(template_path, nil, binding)
71
+ upload! config, '/tmp/application.eye'
72
+
73
+ execute :mv, '/tmp/application.eye', 'eye.rb'
74
+ end
75
+ end
76
+ end
77
+
78
+ before "deploy:publishing", "negroku:eye:setup"
79
+ after "negroku:eye:setup", "eye:load"
80
+
81
+ define_logs(:eye, {
82
+ app: 'eye.log'
83
+ })
84
+
85
+ end
86
+
87
+ end
@@ -11,6 +11,9 @@ namespace :load do
11
11
 
12
12
  # Link .rbenv-vars file
13
13
  set :linked_files, fetch(:linked_files, []) << '.rbenv-vars'
14
+
15
+ # Set the path to rbenv
16
+ set :rbenv_path, "/home/deploy/.rbenv"
14
17
  end
15
18
  end
16
19
 
@@ -60,5 +63,14 @@ namespace :rbenv do
60
63
  end
61
64
  end
62
65
 
66
+ before 'rbenv:vars:add', 'env:changed'
67
+ before 'rbenv:vars:remove', 'env:changed'
68
+
69
+ end
70
+ end
71
+
72
+ namespace :env do
73
+ desc 'Env variables changed'
74
+ task :changed do
63
75
  end
64
76
  end
@@ -15,6 +15,8 @@ namespace :load do
15
15
  # Defines where the unicorn pid will live.
16
16
  set :unicorn_pid, -> { "#{shared_path}/tmp/pids/unicorn.pid" }
17
17
 
18
+ set :unicorn_log, -> { "#{shared_path}/log/unicorn.log" }
19
+
18
20
  set :unicorn_config_path, -> { "#{shared_path}/config/unicorn.rb" }
19
21
 
20
22
  ###################################
@@ -46,7 +48,7 @@ namespace :load do
46
48
  ## capistrano3/nginx variables
47
49
 
48
50
  # Set the app server socket if nginx is being used
49
- set :app_server_socket, -> { fetch(:unicorn_socket) } if was_required? 'capistrano/nginx'
51
+ set :app_server_socket, -> { fetch(:unicorn_socket) } if required? 'capistrano/nginx'
50
52
 
51
53
  end
52
54
  end
@@ -78,7 +80,13 @@ namespace :negroku do
78
80
  # Reload or restart unicorn after the application is published
79
81
  after 'deploy:publishing', 'restart' do
80
82
  invoke 'negroku:unicorn:setup'
81
- invoke fetch(:unicorn_preload)? 'unicorn:restart' : 'unicorn:reload'
83
+ invoke 'unicorn:restart'
84
+ end
85
+
86
+ before 'env:changed', 'hard-restart' do
87
+ invoke 'unicorn:stop'
88
+ sleep 5
89
+ invoke 'unicorn:start'
82
90
  end
83
91
 
84
92
  # Ensure the folders needed exist
@@ -28,6 +28,11 @@ require 'capistrano/nginx'
28
28
  require 'capistrano/delayed-job'
29
29
  require 'whenever/capistrano'
30
30
 
31
+ # Eye monitoring
32
+ require 'negroku/eye'
33
+ require 'negroku/eye/unicorn'
34
+ require 'negroku/eye/delayed-job'
35
+
31
36
  # NEGROKU
32
37
  # Includes negroku defaults and tasks
33
38
  require 'negroku/deploy'
@@ -0,0 +1,28 @@
1
+ cwd = File.expand_path(File.join(File.dirname(__FILE__), %w[ ../ ../ ]))
2
+
3
+ config_path = File.join(cwd, %w{ config dj.yml } )
4
+
5
+ workers_count = if File.exists?(config_path)
6
+ YAML.load_file(config_path).try(:[], :workers) || 5
7
+ else
8
+ 5
9
+ end
10
+
11
+ Eye.application 'delayed_job' do
12
+ working_dir cwd
13
+ stop_on_delete true
14
+
15
+ group 'dj' do
16
+ chain grace: 5.seconds
17
+
18
+ (1 .. workers_count).each do |i|
19
+ process "dj-#{i}" do
20
+ pid_file "tmp/pids/delayed_job.#{i}.pid"
21
+ start_command "rake jobs:work"
22
+ daemonize true
23
+ stop_signals [:INT, 30.seconds, :TERM, 10.seconds, :KILL]
24
+ stdall "log/dj-#{i}.log"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,27 @@
1
+ RAILS_ENV="<%= fetch(:rails_env) %>"
2
+
3
+ process 'unicorn' do
4
+ env rbenv_root: "<%= fetch(:rbenv_path) %>", rbenv_version: "<%=fetch(:rbenv_ruby) %>"
5
+ pid_file "<%= fetch(:unicorn_pid) %>"
6
+ start_command "<%= fetch(:rbenv_prefix) %> bundle exec unicorn -Dc <%= fetch(:unicorn_config_path) %> -E #{RAILS_ENV}"
7
+ stdall "<%= fetch(:unicorn_log) %>"
8
+
9
+ # stop signals:
10
+ # http://unicorn.bogomips.org/SIGNALS.html
11
+ stop_signals [:TERM, 10.seconds]
12
+
13
+ # soft restart
14
+ restart_command "kill -USR2 {PID}"
15
+
16
+ check :cpu, :every => 30, :below => 80, :times => 3
17
+ check :memory, :every => 30, :below => 150.megabytes, :times => [3,5]
18
+
19
+ start_timeout 100.seconds
20
+ restart_grace 30.seconds
21
+
22
+ monitor_children do
23
+ stop_command "kill -QUIT {PID}"
24
+ check :cpu, :every => 30, :below => 80, :times => 3
25
+ check :memory, :every => 30, :below => 150.megabytes, :times => [3,5]
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ require 'eye-http'
2
+
3
+ # Setups Eye global conf if not already
4
+ Eye.config do
5
+ logger '/var/log/eye-global.log'
6
+ http :enable => true, :host => "0.0.0.0", :port => 12345
7
+ end
8
+
9
+ # Adding application
10
+ Eye.application '<%= fetch(:application)%>' do
11
+
12
+ # All options inherits down to the config leafs.
13
+ # except `env`, which merging down
14
+
15
+ stdall '<%= shared_path %>/log/eye.log'
16
+ working_dir '<%= current_path %>'
17
+
18
+ trigger :flapping, times: 10, within: 1.minute, retry_in: 10.minutes
19
+
20
+ check :cpu, every: 10.seconds, below: 100, times: 3 # global check for all processes
21
+
22
+ <% processes.each do |process_name, options| -%>
23
+ <%= partial options[:template], binding %>
24
+ <% end -%>
25
+
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Negroku
2
- VERSION = '2.0.0.pre5'
2
+ VERSION = '2.0.0.pre6'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: negroku
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre5
4
+ version: 2.0.0.pre6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Ignacio Donoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-20 00:00:00.000000000 Z
11
+ date: 2015-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -302,17 +302,24 @@ files:
302
302
  - lib/negroku/cli/env.rb
303
303
  - lib/negroku/cli/stage.rb
304
304
  - lib/negroku/deploy.rb
305
+ - lib/negroku/eye.rb
306
+ - lib/negroku/eye/delayed_job.rb
307
+ - lib/negroku/eye/unicorn.rb
305
308
  - lib/negroku/formatters/simple.rb
306
309
  - lib/negroku/helpers.rb
307
310
  - lib/negroku/helpers/app_directory.rb
308
311
  - lib/negroku/helpers/env.rb
309
312
  - lib/negroku/helpers/logs.rb
310
313
  - lib/negroku/helpers/templates.rb
314
+ - lib/negroku/helpers/watch.rb
311
315
  - lib/negroku/i18n.rb
312
316
  - lib/negroku/locales/en.yml
313
317
  - lib/negroku/tasks/bower.rake
314
318
  - lib/negroku/tasks/bundler.rake
315
319
  - lib/negroku/tasks/delayed_job.rake
320
+ - lib/negroku/tasks/eye.rake
321
+ - lib/negroku/tasks/eye/delayed_job.rake
322
+ - lib/negroku/tasks/eye/unicorn.rake
316
323
  - lib/negroku/tasks/log.rake
317
324
  - lib/negroku/tasks/negroku.rake
318
325
  - lib/negroku/tasks/nginx.rake
@@ -324,6 +331,9 @@ files:
324
331
  - lib/negroku/templates/negroku/Capfile.erb
325
332
  - lib/negroku/templates/negroku/deploy.rb.erb
326
333
  - lib/negroku/templates/negroku/stage.rb.erb
334
+ - lib/negroku/templates/tasks/eye/_delayed_job.erb
335
+ - lib/negroku/templates/tasks/eye/_unicorn.erb
336
+ - lib/negroku/templates/tasks/eye/application.eye.erb
327
337
  - lib/negroku/templates/tasks/unicorn_rails.rb.erb
328
338
  - lib/negroku/templates/tasks/unicorn_rails_activerecord.rb.erb
329
339
  - lib/negroku/version.rb