eye 0.7 → 0.8.celluloid15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/.rubocop.yml +141 -0
 - data/.travis.yml +5 -3
 - data/CHANGES.md +9 -1
 - data/README.md +5 -2
 - data/Rakefile +6 -6
 - data/bin/leye +9 -4
 - data/bin/loader_eye +14 -15
 - data/examples/custom_check.eye +24 -0
 - data/examples/custom_trigger.eye +30 -0
 - data/examples/delayed_job.eye +3 -3
 - data/examples/dependency.eye +10 -11
 - data/examples/leye_example/Eyefile +10 -0
 - data/examples/notify.eye +3 -4
 - data/examples/plugin/main.eye +5 -5
 - data/examples/plugin/plugin.rb +10 -2
 - data/examples/process_thin.rb +8 -8
 - data/examples/processes/em.rb +18 -12
 - data/examples/processes/forking.rb +5 -5
 - data/examples/processes/sample.rb +46 -44
 - data/examples/puma.eye +9 -8
 - data/examples/rbenv.eye +5 -5
 - data/examples/sidekiq.eye +3 -3
 - data/examples/stress_test.eye +4 -4
 - data/examples/syslog.eye +1 -1
 - data/examples/test.eye +1 -2
 - data/examples/thin-farm.eye +7 -8
 - data/examples/triggers.eye +13 -15
 - data/examples/unicorn.eye +12 -13
 - data/eye.gemspec +16 -14
 - data/lib/eye.rb +2 -3
 - data/lib/eye/application.rb +5 -6
 - data/lib/eye/checker.rb +44 -25
 - data/lib/eye/checker/children_count.rb +1 -1
 - data/lib/eye/checker/file_ctime.rb +1 -1
 - data/lib/eye/checker/http.rb +13 -15
 - data/lib/eye/checker/nop.rb +1 -0
 - data/lib/eye/checker/socket.rb +60 -63
 - data/lib/eye/checker/ssl_socket.rb +5 -5
 - data/lib/eye/child_process.rb +6 -4
 - data/lib/eye/cli.rb +74 -46
 - data/lib/eye/cli/commands.rb +4 -5
 - data/lib/eye/cli/render.rb +61 -41
 - data/lib/eye/cli/server.rb +19 -16
 - data/lib/eye/client.rb +1 -0
 - data/lib/eye/config.rb +36 -33
 - data/lib/eye/controller.rb +2 -3
 - data/lib/eye/controller/commands.rb +1 -1
 - data/lib/eye/controller/helpers.rb +2 -2
 - data/lib/eye/controller/load.rb +19 -17
 - data/lib/eye/controller/options.rb +1 -5
 - data/lib/eye/controller/send_command.rb +21 -23
 - data/lib/eye/controller/status.rb +17 -14
 - data/lib/eye/dsl.rb +6 -1
 - data/lib/eye/dsl/application_opts.rb +4 -3
 - data/lib/eye/dsl/chain.rb +2 -2
 - data/lib/eye/dsl/child_process_opts.rb +3 -3
 - data/lib/eye/dsl/config_opts.rb +7 -7
 - data/lib/eye/dsl/group_opts.rb +3 -3
 - data/lib/eye/dsl/helpers.rb +1 -1
 - data/lib/eye/dsl/main.rb +4 -3
 - data/lib/eye/dsl/opts.rb +31 -28
 - data/lib/eye/dsl/process_opts.rb +13 -7
 - data/lib/eye/dsl/pure_opts.rb +13 -9
 - data/lib/eye/dsl/validation.rb +48 -35
 - data/lib/eye/group.rb +23 -8
 - data/lib/eye/group/chain.rb +6 -6
 - data/lib/eye/loader.rb +3 -3
 - data/lib/eye/local.rb +9 -4
 - data/lib/eye/logger.rb +11 -4
 - data/lib/eye/notify.rb +10 -6
 - data/lib/eye/notify/jabber.rb +1 -1
 - data/lib/eye/notify/mail.rb +2 -2
 - data/lib/eye/notify/slack.rb +4 -3
 - data/lib/eye/process.rb +2 -0
 - data/lib/eye/process/children.rb +4 -4
 - data/lib/eye/process/commands.rb +38 -39
 - data/lib/eye/process/config.rb +22 -16
 - data/lib/eye/process/controller.rb +5 -19
 - data/lib/eye/process/data.rb +11 -9
 - data/lib/eye/process/monitor.rb +86 -76
 - data/lib/eye/process/notify.rb +10 -10
 - data/lib/eye/process/scheduler.rb +36 -31
 - data/lib/eye/process/states.rb +7 -5
 - data/lib/eye/process/states_history.rb +9 -3
 - data/lib/eye/process/system.rb +35 -20
 - data/lib/eye/process/trigger.rb +1 -5
 - data/lib/eye/process/watchers.rb +12 -9
 - data/lib/eye/reason.rb +4 -1
 - data/lib/eye/server.rb +3 -2
 - data/lib/eye/system.rb +22 -15
 - data/lib/eye/system_resources.rb +17 -8
 - data/lib/eye/trigger.rb +18 -16
 - data/lib/eye/trigger/check_dependency.rb +7 -4
 - data/lib/eye/trigger/flapping.rb +24 -7
 - data/lib/eye/trigger/starting_guard.rb +7 -6
 - data/lib/eye/trigger/stop_children.rb +2 -2
 - data/lib/eye/trigger/transition.rb +1 -1
 - data/lib/eye/trigger/wait_dependency.rb +3 -2
 - data/lib/eye/utils.rb +4 -3
 - data/lib/eye/utils/alive_array.rb +9 -4
 - data/lib/eye/utils/celluloid_chain.rb +12 -10
 - data/lib/eye/utils/mini_active_support.rb +16 -16
 - data/lib/eye/utils/pmap.rb +2 -0
 - data/lib/eye/utils/tail.rb +2 -2
 - metadata +39 -8
 - 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 
     | 
    
         
            -
                 
     | 
| 
      
 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 
     | 
    
         
            -
                {: 
     | 
| 
      
 38 
     | 
    
         
            +
                objs.each { |obj| block[obj] } if block
         
     | 
| 
      
 39 
     | 
    
         
            +
                { result: res }
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
              rescue Error => ex
         
     | 
| 
       42 
42 
     | 
    
         
             
                log_ex(ex)
         
     | 
| 
       43 
     | 
    
         
            -
                {: 
     | 
| 
      
 43 
     | 
    
         
            +
                { error: ex.message }
         
     | 
| 
       44 
44 
     | 
    
         | 
| 
       45 
45 
     | 
    
         
             
              rescue Celluloid::DeadActorError => ex
         
     | 
| 
       46 
46 
     | 
    
         
             
                log_ex(ex)
         
     | 
| 
       47 
     | 
    
         
            -
                {: 
     | 
| 
      
 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 
     | 
| 
      
 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 
     | 
    
         
            -
                      #  
     | 
| 
       158 
     | 
    
         
            -
                       
     | 
| 
       159 
     | 
    
         
            -
                         
     | 
| 
       160 
     | 
    
         
            -
                         
     | 
| 
       161 
     | 
    
         
            -
             
     | 
| 
       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 
     | 
| 
      
 173 
     | 
    
         
            +
                %r[\A#{str}]
         
     | 
| 
       177 
174 
     | 
    
         
             
              end
         
     | 
| 
       178 
175 
     | 
    
         | 
| 
       179 
176 
     | 
    
         
             
              def exact_regexp(mask)
         
     | 
| 
       180 
177 
     | 
    
         
             
                str = Regexp.escape(mask).gsub('\*', '.*?')
         
     | 
| 
       181 
     | 
    
         
            -
                %r 
     | 
| 
      
 178 
     | 
    
         
            +
                %r[\A#{str}\z]
         
     | 
| 
       182 
179 
     | 
    
         
             
              end
         
     | 
| 
      
 180 
     | 
    
         
            +
             
     | 
| 
       183 
181 
     | 
    
         
             
            end
         
     | 
| 
         @@ -2,18 +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 
     | 
| 
      
 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 
     | 
    
         
            -
                  : 
     | 
| 
       9 
     | 
    
         
            -
                  : 
     | 
| 
       10 
     | 
    
         
            -
                  : 
     | 
| 
       11 
     | 
    
         
            -
                  : 
     | 
| 
       12 
     | 
    
         
            -
                  : 
     | 
| 
       13 
     | 
    
         
            -
                  : 
     | 
| 
       14 
     | 
    
         
            -
                  : 
     | 
| 
       15 
     | 
    
         
            -
                  : 
     | 
| 
       16 
     | 
    
         
            -
                  : 
     | 
| 
      
 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
         
     | 
| 
       17 
19 
     | 
    
         
             
                }
         
     | 
| 
       18 
20 
     | 
    
         | 
| 
       19 
21 
     | 
    
         
             
                res[:config_yaml] = YAML.dump(current_config.to_h) if h[:config].present?
         
     | 
| 
         @@ -22,17 +24,18 @@ module Eye::Controller::Status 
     | 
|
| 
       22 
24 
     | 
    
         
             
              end
         
     | 
| 
       23 
25 
     | 
    
         | 
| 
       24 
26 
     | 
    
         
             
              def info_data(*args)
         
     | 
| 
       25 
     | 
    
         
            -
                 
     | 
| 
      
 27 
     | 
    
         
            +
                h = args.extract_options!
         
     | 
| 
      
 28 
     | 
    
         
            +
                { subtree: info_objects(*args).map { |a| a.status_data(h) } }
         
     | 
| 
       26 
29 
     | 
    
         
             
              end
         
     | 
| 
       27 
30 
     | 
    
         | 
| 
       28 
31 
     | 
    
         
             
              def short_data(*args)
         
     | 
| 
       29 
     | 
    
         
            -
                {: 
     | 
| 
      
 32 
     | 
    
         
            +
                { subtree: info_objects(*args).select { |o| o.class == Eye::Application }.map(&:status_data_short) }
         
     | 
| 
       30 
33 
     | 
    
         
             
              end
         
     | 
| 
       31 
34 
     | 
    
         | 
| 
       32 
35 
     | 
    
         
             
              def history_data(*args)
         
     | 
| 
       33 
36 
     | 
    
         
             
                res = {}
         
     | 
| 
       34 
37 
     | 
    
         
             
                history_objects(*args).each do |process|
         
     | 
| 
       35 
     | 
    
         
            -
                  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 }
         
     | 
| 
       36 
39 
     | 
    
         
             
                end
         
     | 
| 
       37 
40 
     | 
    
         
             
                res
         
     | 
| 
       38 
41 
     | 
    
         
             
              end
         
     | 
| 
         @@ -42,7 +45,7 @@ private 
     | 
|
| 
       42 
45 
     | 
    
         
             
              def info_objects(*args)
         
     | 
| 
       43 
46 
     | 
    
         
             
                res = []
         
     | 
| 
       44 
47 
     | 
    
         
             
                return @applications if args.empty?
         
     | 
| 
       45 
     | 
    
         
            -
                matched_objects(*args){|obj| res << obj }
         
     | 
| 
      
 48 
     | 
    
         
            +
                matched_objects(*args) { |obj| res << obj }
         
     | 
| 
       46 
49 
     | 
    
         
             
                res
         
     | 
| 
       47 
50 
     | 
    
         
             
              end
         
     | 
| 
       48 
51 
     | 
    
         | 
    
        data/lib/eye/dsl.rb
    CHANGED
    
    | 
         @@ -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 = '')
         
     | 
| 
         @@ -36,7 +37,9 @@ class Eye::Dsl 
     | 
|
| 
       36 
37 
     | 
    
         | 
| 
       37 
38 
     | 
    
         
             
                  Eye.parsed_config.transform!
         
     | 
| 
       38 
39 
     | 
    
         
             
                  Eye.parsed_config.validate!
         
     | 
| 
       39 
     | 
    
         
            -
                  Eye.parsed_config
         
     | 
| 
      
 40 
     | 
    
         
            +
                  parsed_config = Eye.parsed_config
         
     | 
| 
      
 41 
     | 
    
         
            +
                  Eye.parsed_config = nil # remove object for better GC
         
     | 
| 
      
 42 
     | 
    
         
            +
                  parsed_config
         
     | 
| 
       40 
43 
     | 
    
         
             
                end
         
     | 
| 
       41 
44 
     | 
    
         | 
| 
       42 
45 
     | 
    
         
             
                def parse_apps(*args)
         
     | 
| 
         @@ -46,7 +49,9 @@ class Eye::Dsl 
     | 
|
| 
       46 
49 
     | 
    
         
             
                def check_name(name)
         
     | 
| 
       47 
50 
     | 
    
         
             
                  raise Error, "':' is not allowed in name '#{name}'" if name.to_s.include?(':')
         
     | 
| 
       48 
51 
     | 
    
         
             
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
       49 
53 
     | 
    
         
             
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
       50 
55 
     | 
    
         
             
            end
         
     | 
| 
       51 
56 
     | 
    
         | 
| 
       52 
57 
     | 
    
         
             
            # 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 
     | 
    
         
            -
               
     | 
| 
       38 
     | 
    
         
            -
               
     | 
| 
      
 37 
     | 
    
         
            +
              alias_method :xgroup, :nop
         
     | 
| 
      
 38 
     | 
    
         
            +
              alias_method :xprocess, :nop
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
       39 
40 
     | 
    
         
             
            end
         
     | 
    
        data/lib/eye/dsl/chain.rb
    CHANGED
    
    
| 
         @@ -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 
     | 
    
         
            -
             
     | 
| 
      
 5 
     | 
    
         
            +
                 :stop_signals, :stop_grace, :stop_timeout, :restart_timeout]
         
     | 
| 
       6 
6 
     | 
    
         
             
              end
         
     | 
| 
       7 
7 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
              def triggers(* 
     | 
| 
      
 8 
     | 
    
         
            +
              def triggers(*_args)
         
     | 
| 
       9 
9 
     | 
    
         
             
                raise Eye::Dsl::Error, 'triggers not allowed in monitor_children'
         
     | 
| 
       10 
10 
     | 
    
         
             
              end
         
     | 
| 
       11 
     | 
    
         
            -
               
     | 
| 
      
 11 
     | 
    
         
            +
              alias_method :trigger, :triggers
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
            end
         
     | 
    
        data/lib/eye/dsl/config_opts.rb
    CHANGED
    
    | 
         @@ -10,13 +10,13 @@ class Eye::Dsl::ConfigOpts < Eye::Dsl::PureOpts 
     | 
|
| 
       10 
10 
     | 
    
         
             
                  @config[:logger] = args
         
     | 
| 
       11 
11 
     | 
    
         
             
                end
         
     | 
| 
       12 
12 
     | 
    
         
             
              end
         
     | 
| 
       13 
     | 
    
         
            -
               
     | 
| 
      
 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,  
     | 
| 
      
 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(: 
     | 
| 
      
 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 
     | 
| 
       40 
     | 
    
         
            -
                validate_hash = notify_hash.merge(contact_opts).merge(: 
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 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)
         
     | 
    
        data/lib/eye/dsl/group_opts.rb
    CHANGED
    
    
    
        data/lib/eye/dsl/helpers.rb
    CHANGED
    
    
    
        data/lib/eye/dsl/main.rb
    CHANGED
    
    | 
         @@ -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 
     | 
    
         
            -
               
     | 
| 
       23 
     | 
    
         
            -
               
     | 
| 
      
 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 
     | 
    
         
            -
               
     | 
| 
      
 57 
     | 
    
         
            +
              alias_method :settings, :config
         
     | 
| 
       57 
58 
     | 
    
         | 
| 
       58 
59 
     | 
    
         
             
              def shared
         
     | 
| 
       59 
60 
     | 
    
         
             
                require 'ostruct'
         
     | 
    
        data/lib/eye/dsl/opts.rb
    CHANGED
    
    | 
         @@ -1,28 +1,28 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            class Eye::Dsl::Opts < Eye::Dsl::PureOpts
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
              STR_OPTIONS = [ 
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
      
 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 = [ 
     | 
| 
      
 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 = [ 
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         
            -
                #  
     | 
| 
      
 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 
     | 
    
         
            -
               
     | 
| 
       66 
     | 
    
         
            -
               
     | 
| 
       67 
     | 
    
         
            -
               
     | 
| 
       68 
     | 
    
         
            -
               
     | 
| 
      
 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,  
     | 
| 
      
 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,  
     | 
| 
      
 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 
     | 
    
         
            -
               
     | 
| 
       125 
     | 
    
         
            -
               
     | 
| 
      
 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( 
     | 
| 
      
 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 
     | 
    
         
            -
             
     | 
| 
      
 184 
     | 
    
         
            +
                          File.expand_path(filename)].uniq
         
     | 
| 
       187 
185 
     | 
    
         
             
                filenames = fnames.select { |f| File.exist?(f) }
         
     | 
| 
       188 
186 
     | 
    
         | 
| 
       189 
187 
     | 
    
         
             
                if filenames.size < 1
         
     | 
| 
       190 
     | 
    
         
            -
                   
     | 
| 
      
 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,  
     | 
| 
      
 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 
     | 
    
         
            -
                   
     | 
| 
       222 
     | 
    
         
            -
             
     | 
| 
      
 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 
     | 
    
         |