eye 0.8.pre2 → 0.8.rc

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +141 -0
  3. data/.travis.yml +5 -3
  4. data/README.md +1 -2
  5. data/Rakefile +5 -5
  6. data/bin/leye +9 -4
  7. data/bin/loader_eye +14 -15
  8. data/examples/custom_check.eye +24 -0
  9. data/examples/custom_trigger.eye +3 -1
  10. data/examples/delayed_job.eye +3 -3
  11. data/examples/dependency.eye +10 -11
  12. data/examples/leye_example/Eyefile +10 -0
  13. data/examples/notify.eye +3 -4
  14. data/examples/plugin/main.eye +5 -5
  15. data/examples/plugin/plugin.rb +10 -2
  16. data/examples/process_thin.rb +8 -8
  17. data/examples/processes/em.rb +18 -12
  18. data/examples/processes/forking.rb +5 -5
  19. data/examples/processes/sample.rb +46 -44
  20. data/examples/puma.eye +9 -8
  21. data/examples/rbenv.eye +5 -5
  22. data/examples/sidekiq.eye +3 -3
  23. data/examples/stress_test.eye +4 -4
  24. data/examples/syslog.eye +1 -1
  25. data/examples/test.eye +1 -2
  26. data/examples/thin-farm.eye +7 -8
  27. data/examples/triggers.eye +13 -15
  28. data/examples/unicorn.eye +12 -13
  29. data/eye.gemspec +14 -12
  30. data/lib/eye.rb +2 -3
  31. data/lib/eye/application.rb +5 -6
  32. data/lib/eye/checker.rb +36 -19
  33. data/lib/eye/checker/children_count.rb +1 -1
  34. data/lib/eye/checker/file_ctime.rb +1 -1
  35. data/lib/eye/checker/http.rb +13 -15
  36. data/lib/eye/checker/nop.rb +1 -0
  37. data/lib/eye/checker/socket.rb +60 -63
  38. data/lib/eye/checker/ssl_socket.rb +5 -5
  39. data/lib/eye/child_process.rb +6 -4
  40. data/lib/eye/cli.rb +50 -41
  41. data/lib/eye/cli/commands.rb +4 -5
  42. data/lib/eye/cli/render.rb +61 -41
  43. data/lib/eye/cli/server.rb +19 -16
  44. data/lib/eye/client.rb +1 -0
  45. data/lib/eye/config.rb +19 -19
  46. data/lib/eye/controller.rb +2 -3
  47. data/lib/eye/controller/commands.rb +1 -1
  48. data/lib/eye/controller/helpers.rb +2 -2
  49. data/lib/eye/controller/load.rb +18 -12
  50. data/lib/eye/controller/options.rb +1 -5
  51. data/lib/eye/controller/send_command.rb +21 -23
  52. data/lib/eye/controller/status.rb +17 -15
  53. data/lib/eye/dsl.rb +3 -0
  54. data/lib/eye/dsl/application_opts.rb +4 -3
  55. data/lib/eye/dsl/chain.rb +2 -2
  56. data/lib/eye/dsl/child_process_opts.rb +3 -3
  57. data/lib/eye/dsl/config_opts.rb +7 -7
  58. data/lib/eye/dsl/group_opts.rb +3 -3
  59. data/lib/eye/dsl/helpers.rb +1 -1
  60. data/lib/eye/dsl/main.rb +4 -3
  61. data/lib/eye/dsl/opts.rb +31 -28
  62. data/lib/eye/dsl/process_opts.rb +13 -7
  63. data/lib/eye/dsl/pure_opts.rb +13 -9
  64. data/lib/eye/dsl/validation.rb +48 -35
  65. data/lib/eye/group.rb +20 -6
  66. data/lib/eye/group/chain.rb +6 -6
  67. data/lib/eye/loader.rb +1 -1
  68. data/lib/eye/local.rb +9 -4
  69. data/lib/eye/logger.rb +11 -4
  70. data/lib/eye/notify.rb +10 -6
  71. data/lib/eye/notify/jabber.rb +1 -1
  72. data/lib/eye/notify/mail.rb +2 -2
  73. data/lib/eye/notify/slack.rb +4 -3
  74. data/lib/eye/process.rb +2 -0
  75. data/lib/eye/process/children.rb +4 -4
  76. data/lib/eye/process/commands.rb +28 -31
  77. data/lib/eye/process/config.rb +21 -19
  78. data/lib/eye/process/data.rb +11 -9
  79. data/lib/eye/process/monitor.rb +30 -29
  80. data/lib/eye/process/notify.rb +10 -10
  81. data/lib/eye/process/scheduler.rb +36 -31
  82. data/lib/eye/process/states.rb +5 -4
  83. data/lib/eye/process/states_history.rb +9 -3
  84. data/lib/eye/process/system.rb +5 -4
  85. data/lib/eye/process/trigger.rb +1 -5
  86. data/lib/eye/process/watchers.rb +6 -9
  87. data/lib/eye/reason.rb +4 -1
  88. data/lib/eye/server.rb +2 -1
  89. data/lib/eye/system.rb +16 -13
  90. data/lib/eye/system_resources.rb +13 -8
  91. data/lib/eye/trigger.rb +18 -16
  92. data/lib/eye/trigger/check_dependency.rb +7 -4
  93. data/lib/eye/trigger/flapping.rb +24 -7
  94. data/lib/eye/trigger/starting_guard.rb +7 -6
  95. data/lib/eye/trigger/stop_children.rb +2 -2
  96. data/lib/eye/trigger/transition.rb +1 -1
  97. data/lib/eye/trigger/wait_dependency.rb +3 -2
  98. data/lib/eye/utils.rb +4 -3
  99. data/lib/eye/utils/alive_array.rb +9 -4
  100. data/lib/eye/utils/celluloid_chain.rb +12 -10
  101. data/lib/eye/utils/mini_active_support.rb +16 -16
  102. data/lib/eye/utils/pmap.rb +2 -0
  103. data/lib/eye/utils/tail.rb +2 -2
  104. metadata +34 -4
  105. data/lib/eye/utils/leak_19.rb +0 -10
@@ -2,7 +2,7 @@ module Eye::Controller::Options
2
2
 
3
3
  def set_opt_logger(logger_args)
4
4
  # do not apply logger, if in stdout state
5
- if !%w{stdout stderr}.include?(Eye::Logger.dev)
5
+ unless %w[stdout stderr].include?(Eye::Logger.dev)
6
6
  Eye::Logger.link_logger(*logger_args)
7
7
  end
8
8
  end
@@ -11,8 +11,4 @@ module Eye::Controller::Options
11
11
  Eye::Logger.log_level = level
12
12
  end
13
13
 
14
- def set_opt_http(opts = {})
15
- warn "Warning, set http options not in reel-eye gem" if opts.present?
16
- end
17
-
18
14
  end
@@ -35,16 +35,16 @@ private
35
35
  def matched_objects(*args, &block)
36
36
  objs = find_objects(*args)
37
37
  res = objs.map(&:full_name)
38
- objs.each{|obj| block[obj] } if block
39
- {:result => res}
38
+ objs.each { |obj| block[obj] } if block
39
+ { result: res }
40
40
 
41
41
  rescue Error => ex
42
42
  log_ex(ex)
43
- {:error => ex.message}
43
+ { error: ex.message }
44
44
 
45
45
  rescue Celluloid::DeadActorError => ex
46
46
  log_ex(ex)
47
- {:error => "'#{ex.message}', try again!"}
47
+ { error: "'#{ex.message}', try again!" }
48
48
  end
49
49
 
50
50
  def remove_object_from_tree(obj)
@@ -56,12 +56,12 @@ private
56
56
  end
57
57
 
58
58
  if klass == Eye::Group
59
- @applications.each{|app| app.groups.delete(obj) }
59
+ @applications.each { |app| app.groups.delete(obj) }
60
60
  @current_config.delete_group(obj.name)
61
61
  end
62
62
 
63
63
  if klass == Eye::Process
64
- @applications.each{|app| app.groups.each{|gr| gr.processes.delete(obj) }}
64
+ @applications.each { |app| app.groups.each { |gr| gr.processes.delete(obj) } }
65
65
  @current_config.delete_process(obj.name)
66
66
  end
67
67
  end
@@ -76,14 +76,14 @@ private
76
76
 
77
77
  if obj_strs.size == 1 && (obj_strs[0].to_s.strip == 'all' || obj_strs[0].to_s.strip == '*')
78
78
  if h[:application]
79
- return @applications.select { |app| app.name == h[:application]}
79
+ return @applications.select { |app| app.name == h[:application] }
80
80
  else
81
81
  return @applications.dup
82
82
  end
83
83
  end
84
84
 
85
85
  res = Eye::Utils::AliveArray.new
86
- obj_strs.map{|c| c.to_s.split(',')}.flatten.each do |mask|
86
+ obj_strs.map { |c| c.to_s.split(',') }.flatten.each do |mask|
87
87
  objs = find_objects_by_mask(mask.to_s.strip)
88
88
  objs.select! { |obj| obj.app_name == h[:application] } if h[:application]
89
89
  res += objs
@@ -110,14 +110,15 @@ private
110
110
 
111
111
  # remove inherited targets
112
112
  res.each do |obj|
113
- sub_object = res.any?{|a| a.sub_object?(obj) }
113
+ sub_object = res.any? { |a| a.sub_object?(obj) }
114
114
  final << obj unless sub_object
115
115
  end
116
116
 
117
117
  res = final
118
118
 
119
119
  # try to remove objects with different applications
120
- apps, objs = Eye::Utils::AliveArray.new, Eye::Utils::AliveArray.new
120
+ apps = Eye::Utils::AliveArray.new
121
+ objs = Eye::Utils::AliveArray.new
121
122
  res.each do |obj|
122
123
  if obj.is_a?(Eye::Application)
123
124
  apps << obj
@@ -141,11 +142,11 @@ private
141
142
  r = left_regexp(mask)
142
143
 
143
144
  # find app
144
- res = @applications.select{|a| a.name =~ r || a.full_name =~ r }
145
+ res = @applications.select { |a| a.name =~ r || a.full_name =~ r }
145
146
 
146
147
  # find group
147
148
  @applications.each do |a|
148
- res += a.groups.select{|gr| gr.name =~ r || gr.full_name =~ r }
149
+ res += a.groups.select { |gr| gr.name =~ r || gr.full_name =~ r }
149
150
  end
150
151
 
151
152
  # find process
@@ -154,16 +155,12 @@ private
154
155
  gr.processes.each do |p|
155
156
  res << p if p.name =~ r || p.full_name =~ r
156
157
 
157
- # child matching
158
- if p.children.present?
159
- children = p.children.values
160
- res += children.select do |ch|
161
- name = ch.name rescue ''
162
- full_name = ch.full_name rescue ''
163
- name =~ r || full_name =~ r
164
- end
158
+ # children matching
159
+ p.children.each_value do |ch|
160
+ name = ch.name rescue ''
161
+ full_name = ch.full_name rescue ''
162
+ res << ch if name =~ r || full_name =~ r
165
163
  end
166
-
167
164
  end
168
165
  end
169
166
  end
@@ -173,11 +170,12 @@ private
173
170
 
174
171
  def left_regexp(mask)
175
172
  str = Regexp.escape(mask).gsub('\*', '.*?')
176
- %r|\A#{str}|
173
+ %r[\A#{str}]
177
174
  end
178
175
 
179
176
  def exact_regexp(mask)
180
177
  str = Regexp.escape(mask).gsub('\*', '.*?')
181
- %r|\A#{str}\z|
178
+ %r[\A#{str}\z]
182
179
  end
180
+
183
181
  end
@@ -2,19 +2,20 @@ module Eye::Controller::Status
2
2
 
3
3
  def debug_data(*args)
4
4
  h = args.extract_options!
5
- actors = Celluloid::Actor.all.map{|actor| actor.wrapped_object.class.to_s }.group_by{|a| a}.map{|k,v| [k, v.size]}.sort_by{ |a| a[1] }.reverse
5
+ actors = Celluloid::Actor.all.map { |actor| actor.wrapped_object.class.to_s }.group_by { |a| a }
6
+ actors = actors.map { |k, v| [k, v.size] }.sort_by { |a| a[1] }.reverse
6
7
 
7
8
  res = {
8
- :about => Eye::ABOUT,
9
- :resources => Eye::SystemResources.resources($$),
10
- :ruby => RUBY_DESCRIPTION,
11
- :gems => %w|Celluloid Celluloid::IO StateMachine NIO Timers Sigar|.map{|c| gem_version(c) },
12
- :logger => Eye::Logger.args.present? ? [Eye::Logger.dev.to_s, *Eye::Logger.args] : Eye::Logger.dev.to_s,
13
- :dir => Eye::Local.dir,
14
- :pid_path => Eye::Local::pid_path,
15
- :sock_path => Eye::Local::socket_path,
16
- :actors => actors,
17
- :celluloid_backported => $CELLULOID_BACKPORTED
9
+ about: Eye::ABOUT,
10
+ resources: Eye::SystemResources.resources($$),
11
+ ruby: RUBY_DESCRIPTION,
12
+ gems: %w[Celluloid Celluloid::IO StateMachine NIO Timers Sigar].map { |c| gem_version(c) },
13
+ logger: Eye::Logger.args.present? ? [Eye::Logger.dev.to_s, *Eye::Logger.args] : Eye::Logger.dev.to_s,
14
+ home: Eye::Local.home,
15
+ dir: Eye::Local.dir,
16
+ pid_path: Eye::Local.pid_path,
17
+ sock_path: Eye::Local.socket_path,
18
+ actors: actors
18
19
  }
19
20
 
20
21
  res[:config_yaml] = YAML.dump(current_config.to_h) if h[:config].present?
@@ -23,17 +24,18 @@ module Eye::Controller::Status
23
24
  end
24
25
 
25
26
  def info_data(*args)
26
- {:subtree => info_objects(*args).map{|a| a.status_data } }
27
+ h = args.extract_options!
28
+ { subtree: info_objects(*args).map { |a| a.status_data(h) } }
27
29
  end
28
30
 
29
31
  def short_data(*args)
30
- {:subtree => info_objects(*args).select{ |o| o.class == Eye::Application }.map{|a| a.status_data_short } }
32
+ { subtree: info_objects(*args).select { |o| o.class == Eye::Application }.map(&:status_data_short) }
31
33
  end
32
34
 
33
35
  def history_data(*args)
34
36
  res = {}
35
37
  history_objects(*args).each do |process|
36
- res[process.full_name] = process.schedule_history.reject{|c| c[:state] == :check_crash }
38
+ res[process.full_name] = process.schedule_history.reject { |c| c[:state] == :check_crash }
37
39
  end
38
40
  res
39
41
  end
@@ -43,7 +45,7 @@ private
43
45
  def info_objects(*args)
44
46
  res = []
45
47
  return @applications if args.empty?
46
- matched_objects(*args){|obj| res << obj }
48
+ matched_objects(*args) { |obj| res << obj }
47
49
  res
48
50
  end
49
51
 
@@ -18,6 +18,7 @@ class Eye::Dsl
18
18
  class Error < Exception; end
19
19
 
20
20
  class << self
21
+
21
22
  attr_accessor :verbose
22
23
 
23
24
  def debug(msg = '')
@@ -46,7 +47,9 @@ class Eye::Dsl
46
47
  def check_name(name)
47
48
  raise Error, "':' is not allowed in name '#{name}'" if name.to_s.include?(':')
48
49
  end
50
+
49
51
  end
52
+
50
53
  end
51
54
 
52
55
  # extend here global module
@@ -30,10 +30,11 @@ class Eye::Dsl::ApplicationOpts < Eye::Dsl::Opts
30
30
 
31
31
  def process(name, &block)
32
32
  res = nil
33
- group('__default__'){ res = process(name.to_s, &block) }
33
+ group('__default__') { res = process(name.to_s, &block) }
34
34
  res
35
35
  end
36
36
 
37
- alias xgroup nop
38
- alias xprocess nop
37
+ alias_method :xgroup, :nop
38
+ alias_method :xprocess, :nop
39
+
39
40
  end
@@ -5,8 +5,8 @@ module Eye::Dsl::Chain
5
5
 
6
6
  acts.each do |act|
7
7
  @config[:chain] ||= {}
8
- @config[:chain][act] = opts.merge(:action => act)
8
+ @config[:chain][act] = opts.merge(action: act)
9
9
  end
10
10
  end
11
11
 
12
- end
12
+ end
@@ -2,12 +2,12 @@ class Eye::Dsl::ChildProcessOpts < Eye::Dsl::Opts
2
2
 
3
3
  def allow_options
4
4
  [:stop_command, :restart_command, :children_update_period,
5
- :stop_signals, :stop_grace, :stop_timeout, :restart_timeout]
5
+ :stop_signals, :stop_grace, :stop_timeout, :restart_timeout]
6
6
  end
7
7
 
8
- def triggers(*args)
8
+ def triggers(*_args)
9
9
  raise Eye::Dsl::Error, 'triggers not allowed in monitor_children'
10
10
  end
11
- alias trigger triggers
11
+ alias_method :trigger, :triggers
12
12
 
13
13
  end
@@ -10,13 +10,13 @@ class Eye::Dsl::ConfigOpts < Eye::Dsl::PureOpts
10
10
  @config[:logger] = args
11
11
  end
12
12
  end
13
- alias logger= logger
13
+ alias_method :logger=, :logger
14
14
 
15
15
  def syslog(name = 'eye', *args)
16
16
  require 'syslog/logger'
17
17
  Syslog::Logger.new(name, *args)
18
18
  rescue LoadError
19
- raise Eye::Dsl::Error, "logger syslog requires Ruby >= 2.0"
19
+ raise Eye::Dsl::Error, 'logger syslog requires Ruby >= 2.0'
20
20
  end
21
21
 
22
22
  # ==== contact options ==============================
@@ -24,7 +24,7 @@ class Eye::Dsl::ConfigOpts < Eye::Dsl::PureOpts
24
24
  create_options_methods([type], Hash)
25
25
 
26
26
  define_method("set_#{type}") do |value|
27
- value = value.merge(:type => type)
27
+ value = value.merge(type: type)
28
28
  super(value)
29
29
  Eye::Notify.validate!(value)
30
30
  end
@@ -36,14 +36,14 @@ class Eye::Dsl::ConfigOpts < Eye::Dsl::PureOpts
36
36
  raise Eye::Dsl::Error, "unknown contact_type #{contact_type}" unless Eye::Notify::TYPES[contact_type]
37
37
  raise Eye::Dsl::Error, 'contact should be a String' unless contact.is_a?(String)
38
38
 
39
- notify_hash = @config[contact_type] || (@parent && @parent.config[contact_type]) || Eye::parsed_config.settings[contact_type] || {}
40
- validate_hash = notify_hash.merge(contact_opts).merge(:type => contact_type)
39
+ notify_hash = @config[contact_type] || (@parent && @parent.config[contact_type]) || Eye.parsed_config.settings[contact_type] || {}
40
+ validate_hash = notify_hash.merge(contact_opts).merge(type: contact_type)
41
41
 
42
42
  Eye::Notify.validate!(validate_hash)
43
43
 
44
44
  @config[:contacts] ||= {}
45
- @config[:contacts][contact_name.to_s] = {name: contact_name.to_s, type: contact_type,
46
- contact: contact, opts: contact_opts}
45
+ @config[:contacts][contact_name.to_s] = { name: contact_name.to_s, type: contact_type,
46
+ contact: contact, opts: contact_opts }
47
47
  end
48
48
 
49
49
  def contact_group(contact_group_name, &block)
@@ -25,8 +25,8 @@ class Eye::Dsl::GroupOpts < Eye::Dsl::Opts
25
25
  opts
26
26
  end
27
27
 
28
- alias xprocess nop
29
- alias application parent
30
- alias app application
28
+ alias_method :xprocess, :nop
29
+ alias_method :application, :parent
30
+ alias_method :app, :application
31
31
 
32
32
  end
@@ -14,7 +14,7 @@ end
14
14
  def example_process(proxy, name)
15
15
  proxy.process(name) do
16
16
  pid_file "/tmp/#{name}.pid"
17
- start_command "sleep 100"
17
+ start_command 'sleep 100'
18
18
  daemonize true
19
19
  end
20
20
  end
@@ -1,4 +1,5 @@
1
1
  module Eye::Dsl::Main
2
+
2
3
  attr_accessor :parsed_config, :parsed_filename, :parsed_default_app
3
4
 
4
5
  def application(name, &block)
@@ -19,8 +20,8 @@ module Eye::Dsl::Main
19
20
  Eye::Dsl.debug { "<= app: #{name}" }
20
21
  end
21
22
 
22
- alias project application
23
- alias app application
23
+ alias_method :project, :application
24
+ alias_method :app, :application
24
25
 
25
26
  def load(glob = '')
26
27
  return if glob.blank?
@@ -53,7 +54,7 @@ module Eye::Dsl::Main
53
54
  Eye::Dsl.debug { '<= config' }
54
55
  end
55
56
 
56
- alias settings config
57
+ alias_method :settings, :config
57
58
 
58
59
  def shared
59
60
  require 'ostruct'
@@ -1,28 +1,28 @@
1
1
  class Eye::Dsl::Opts < Eye::Dsl::PureOpts
2
2
 
3
- STR_OPTIONS = [ :pid_file, :working_dir, :stdout, :stderr, :stdall, :stdin, :start_command,
4
- :stop_command, :restart_command, :uid, :gid ]
3
+ STR_OPTIONS = [:pid_file, :working_dir, :stdout, :stderr, :stdall, :stdin, :start_command,
4
+ :stop_command, :restart_command, :uid, :gid]
5
5
  create_options_methods(STR_OPTIONS, String)
6
6
 
7
- BOOL_OPTIONS = [ :daemonize, :keep_alive, :auto_start, :stop_on_delete, :clear_pid, :preserve_fds, :use_leaf_child, :clear_env, :check_identity ]
7
+ BOOL_OPTIONS = [:daemonize, :keep_alive, :auto_start, :stop_on_delete, :clear_pid, :preserve_fds, :use_leaf_child,
8
+ :clear_env, :check_identity]
8
9
  create_options_methods(BOOL_OPTIONS, [TrueClass, FalseClass])
9
10
 
10
- INTERVAL_OPTIONS = [ :check_alive_period, :start_timeout, :restart_timeout, :stop_timeout, :start_grace,
11
- :restart_grace, :stop_grace, :children_update_period, :restore_in,
12
- :auto_update_pidfile_grace, :revert_fuckup_pidfile_grace, :check_identity_period, :check_identity_grace ]
11
+ INTERVAL_OPTIONS = [:check_alive_period, :start_timeout, :restart_timeout, :stop_timeout, :start_grace,
12
+ :restart_grace, :stop_grace, :children_update_period, :restore_in,
13
+ :auto_update_pidfile_grace, :revert_fuckup_pidfile_grace, :check_identity_period, :check_identity_grace]
13
14
  create_options_methods(INTERVAL_OPTIONS, [Fixnum, Float])
14
15
 
15
16
  create_options_methods([:environment], Hash)
16
17
  create_options_methods([:umask], Fixnum)
17
18
 
18
-
19
19
  def initialize(name = nil, parent = nil)
20
20
  super(name, parent)
21
21
 
22
22
  @config[:application] = parent.name if parent.is_a?(Eye::Dsl::ApplicationOpts) && parent.name != '__default__'
23
23
  @config[:group] = parent.name if parent.is_a?(Eye::Dsl::GroupOpts)
24
24
 
25
- # hack for full name
25
+ # HACK: for full name
26
26
  @full_name = parent.full_name if @name == '__default__' && parent.respond_to?(:full_name)
27
27
  end
28
28
 
@@ -62,10 +62,10 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
62
62
  @config[:triggers].try :delete, nac[:name]
63
63
  end
64
64
 
65
- alias check checks
66
- alias nocheck nochecks
67
- alias trigger triggers
68
- alias notrigger notriggers
65
+ alias_method :check, :checks
66
+ alias_method :nocheck, :nochecks
67
+ alias_method :trigger, :triggers
68
+ alias_method :notrigger, :notriggers
69
69
 
70
70
  def command(cmd, arg)
71
71
  @config[:user_commands] ||= {}
@@ -95,16 +95,14 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
95
95
  end
96
96
 
97
97
  def set_stop_command(cmd)
98
- raise Eye::Dsl::Error, "cannot use both stop_signals and stop_command" if @config[:stop_signals]
98
+ raise Eye::Dsl::Error, 'cannot use both stop_signals and stop_command' if @config[:stop_signals]
99
99
  super
100
100
  end
101
101
 
102
102
  def stop_signals(*args)
103
- raise Eye::Dsl::Error, "cannot use both stop_signals and stop_command" if @config[:stop_command]
103
+ raise Eye::Dsl::Error, 'cannot use both stop_signals and stop_command' if @config[:stop_command]
104
104
 
105
- if args.count == 0
106
- return @config[:stop_signals]
107
- end
105
+ return @config[:stop_signals] if args.count == 0
108
106
 
109
107
  signals = Array(args).flatten
110
108
  validate_signals(signals)
@@ -121,8 +119,8 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
121
119
  @config[:environment].merge!(value)
122
120
  end
123
121
 
124
- alias dir working_dir
125
- alias env environment
122
+ alias_method :dir, :working_dir
123
+ alias_method :env, :environment
126
124
 
127
125
  def set_stdall(value)
128
126
  super
@@ -150,7 +148,7 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
150
148
  end
151
149
 
152
150
  def scoped(&block)
153
- h = self.class.new(self.name, self)
151
+ h = self.class.new(name, self)
154
152
  h.instance_eval(&block)
155
153
  Eye::Utils.deep_merge!(config, h.config, [:groups, :processes])
156
154
  end
@@ -166,7 +164,7 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
166
164
  host = Eye::Local.host
167
165
 
168
166
  if glob.is_a?(Array)
169
- on_server = !!glob.any?{|elem| elem == host}
167
+ on_server = !!glob.any? { |elem| elem == host }
170
168
  elsif glob.is_a?(Regexp)
171
169
  on_server = !!host.match(glob)
172
170
  elsif glob.is_a?(String) || glob.is_a?(Symbol)
@@ -183,15 +181,15 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
183
181
 
184
182
  def load_env(filename = '~/.env', raise_when_no_file = true)
185
183
  fnames = [File.expand_path(filename, @config[:working_dir]),
186
- File.expand_path(filename)].uniq
184
+ File.expand_path(filename)].uniq
187
185
  filenames = fnames.select { |f| File.exist?(f) }
188
186
 
189
187
  if filenames.size < 1
190
- unless raise_when_no_file
188
+ if raise_when_no_file
189
+ raise Eye::Dsl::Error, "load_env not found in #{fnames}"
190
+ else
191
191
  warn "load_env not found file: '#{filenames.first}'"
192
192
  return
193
- else
194
- raise Eye::Dsl::Error, "load_env not found in #{fnames}"
195
193
  end
196
194
  end
197
195
  raise Eye::Dsl::Error, "load_env conflict filenames: #{filenames}" if filenames.size > 1
@@ -213,13 +211,18 @@ private
213
211
 
214
212
  def validate_signals(signals = nil)
215
213
  return unless signals
216
- raise Eye::Dsl::Error, "signals should be Array" unless signals.is_a?(Array)
214
+ raise Eye::Dsl::Error, 'signals should be Array' unless signals.is_a?(Array)
217
215
  s = signals.clone
218
216
  while s.present?
219
217
  sig = s.shift
220
218
  timeout = s.shift
221
- raise Eye::Dsl::Error, "signal should be String, Symbol, Fixnum, not #{sig.inspect}" if sig && ![String, Symbol, Fixnum].include?(sig.class)
222
- raise Eye::Dsl::Error, "signal sleep should be Numeric, not #{timeout.inspect}" if timeout && ![Fixnum, Float].include?(timeout.class)
219
+ if sig && ![String, Symbol, Fixnum].include?(sig.class)
220
+ raise Eye::Dsl::Error, "signal should be String, Symbol, Fixnum, not #{sig.inspect}"
221
+ end
222
+
223
+ if timeout && ![Fixnum, Float].include?(timeout.class)
224
+ raise Eye::Dsl::Error, "signal sleep should be Numeric, not #{timeout.inspect}"
225
+ end
223
226
  end
224
227
  end
225
228