reel-eye 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,9 +28,10 @@ module Eye::Controller::Status
28
28
 
29
29
  str = <<-S
30
30
  About: #{Eye::ABOUT}
31
- Info: #{resources_str(Eye::SystemResources.resources($$), false)}
31
+ Info: #{resources_str(Eye::SystemResources.resources($$))}
32
32
  Ruby: #{RUBY_DESCRIPTION}
33
33
  Logger: #{Eye::Logger.dev}
34
+ Http: #{@http ? "#{@http.host}:#{@http.port}" : '-'}
34
35
  Socket: #{Eye::Settings::socket_path}
35
36
  Pid: #{Eye::Settings::pid_path}
36
37
  Actors: #{actors.inspect}
@@ -98,16 +99,11 @@ private
98
99
  end
99
100
  end
100
101
 
101
- def resources_str(r, mb = true)
102
+ def resources_str(r)
102
103
  return '' if r.blank?
103
104
 
104
105
  res = "#{r[:start_time]}, #{r[:cpu]}%"
105
-
106
- if r[:memory]
107
- mem = mb ? "#{r[:memory] / 1024}Mb" : "#{r[:memory]}Kb"
108
- res += ", #{mem}"
109
- end
110
-
106
+ res += ", #{r[:memory] / 1024}Mb" if r[:memory]
111
107
  res += ", <#{r[:pid]}>"
112
108
 
113
109
  res
@@ -6,6 +6,10 @@ class Eye::Dsl::ApplicationOpts < Eye::Dsl::Opts
6
6
  [:pid_file, :start_command]
7
7
  end
8
8
 
9
+ def not_seed_options
10
+ [:groups]
11
+ end
12
+
9
13
  def group(name, &block)
10
14
  Eye::Dsl.debug "=> group #{name}"
11
15
 
@@ -28,6 +32,6 @@ class Eye::Dsl::ApplicationOpts < Eye::Dsl::Opts
28
32
  group("__default__"){ process(name.to_s, &block) }
29
33
  end
30
34
 
31
- def xgroup(name, &block); end
32
- def xprocess(name, &block); end
35
+ alias xgroup nop
36
+ alias xprocess nop
33
37
  end
@@ -6,6 +6,10 @@ class Eye::Dsl::GroupOpts < Eye::Dsl::Opts
6
6
  [:pid_file, :start_command]
7
7
  end
8
8
 
9
+ def not_seed_options
10
+ [:processes, :chain]
11
+ end
12
+
9
13
  def process(name, &block)
10
14
  Eye::Dsl.debug "=> process #{name}"
11
15
 
@@ -17,11 +21,8 @@ class Eye::Dsl::GroupOpts < Eye::Dsl::Opts
17
21
  Eye::Dsl.debug "<= process #{name}"
18
22
  end
19
23
 
20
- def xprocess(name, &block); end
21
-
22
- def application
23
- parent
24
- end
25
- alias :app :application
24
+ alias xprocess nop
25
+ alias application parent
26
+ alias app application
26
27
 
27
28
  end
data/lib/eye/dsl/main.rb CHANGED
@@ -11,7 +11,7 @@ module Eye::Dsl::Main
11
11
  Eye::Dsl.debug "<= app: #{name}"
12
12
  end
13
13
 
14
- alias :app :application
14
+ alias app application
15
15
 
16
16
  def load(glob = '')
17
17
  return if glob.blank?
data/lib/eye/dsl/opts.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  class Eye::Dsl::Opts < Eye::Dsl::PureOpts
2
2
 
3
3
  STR_OPTIONS = [ :pid_file, :working_dir, :stdout, :stderr, :stdall, :start_command,
4
- :stop_command, :restart_command ]
4
+ :stop_command, :restart_command, :uid, :gid ]
5
5
  create_options_methods(STR_OPTIONS, String)
6
6
 
7
7
  BOOL_OPTIONS = [ :daemonize, :keep_alive, :control_pid, :auto_start, :stop_on_delete]
@@ -11,17 +11,14 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
11
11
  :restart_grace, :stop_grace, :childs_update_period ]
12
12
  create_options_methods(INTERVAL_OPTIONS, [Fixnum, Float])
13
13
 
14
- OTHER_OPTIONS = [ :environment, :stop_signals ]
15
- create_options_methods(OTHER_OPTIONS)
14
+ create_options_methods([:environment], Hash)
15
+ create_options_methods([:stop_signals], Array)
16
+ create_options_methods([:umask], Fixnum)
16
17
 
17
18
 
18
19
  def initialize(name = nil, parent = nil)
19
20
  super(name, parent)
20
21
 
21
- # ensure delete subobjects which can appears from parent config
22
- @config.delete :groups
23
- @config.delete :processes
24
-
25
22
  @config[:application] = parent.name if parent.is_a?(Eye::Dsl::ApplicationOpts)
26
23
  @config[:group] = parent.name if parent.is_a?(Eye::Dsl::GroupOpts)
27
24
 
@@ -30,14 +27,14 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
30
27
  end
31
28
 
32
29
  def checks(type, opts = {})
33
- type = type.to_sym
34
- raise Eye::Dsl::Error, "unknown checker type #{type}" unless Eye::Checker::TYPES[type]
30
+ nac = Eye::Checker.name_and_class(type.to_sym)
31
+ raise Eye::Dsl::Error, "unknown checker type #{type}" unless nac
35
32
 
36
- opts.merge!(:type => type)
33
+ opts.merge!(:type => nac[:type])
37
34
  Eye::Checker.validate!(opts)
38
35
 
39
36
  @config[:checks] ||= {}
40
- @config[:checks][type] = opts
37
+ @config[:checks][nac[:name]] = opts
41
38
  end
42
39
 
43
40
  def triggers(type, opts = {})
@@ -53,9 +50,9 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
53
50
 
54
51
  # clear checks from parent
55
52
  def nochecks(type)
56
- type = type.to_sym
57
- raise Eye::Dsl::Error, "unknown checker type #{type}" unless Eye::Checker::TYPES[type]
58
- @config[:checks].try :delete, type
53
+ nac = Eye::Checker.name_and_class(type.to_sym)
54
+ raise Eye::Dsl::Error, "unknown checker type #{type}" unless nac
55
+ @config[:checks].try :delete, nac[:name]
59
56
  end
60
57
 
61
58
  # clear triggers from parent
@@ -85,7 +82,7 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
85
82
  @config[:environment].merge!(value)
86
83
  end
87
84
 
88
- alias :env :environment
85
+ alias env environment
89
86
 
90
87
  def set_stdall(value)
91
88
  super
@@ -94,6 +91,16 @@ class Eye::Dsl::Opts < Eye::Dsl::PureOpts
94
91
  set_stderr value
95
92
  end
96
93
 
94
+ def set_uid(value)
95
+ raise Eye::Dsl::Error, ":uid not supported by ruby (needed 2.0)" unless Eye::Settings.supported_setsid?
96
+ super
97
+ end
98
+
99
+ def set_gid(value)
100
+ raise Eye::Dsl::Error, ":gid not supported by ruby (needed 2.0)" unless Eye::Settings.supported_setsid?
101
+ super
102
+ end
103
+
97
104
  def scoped(&block)
98
105
  h = self.class.new(self.name, self)
99
106
  h.instance_eval(&block)
@@ -7,15 +7,12 @@ class Eye::Dsl::ProcessOpts < Eye::Dsl::Opts
7
7
  @config[:monitor_children].merge!(opts.config)
8
8
  end
9
9
 
10
- def xmonitor_children(&block); end
10
+ alias xmonitor_children nop
11
11
 
12
12
  def application
13
13
  parent.try(:parent)
14
14
  end
15
- alias :app :application
16
-
17
- def group
18
- parent
19
- end
15
+ alias app application
16
+ alias group parent
20
17
 
21
18
  end
@@ -49,7 +49,12 @@ class Eye::Dsl::PureOpts
49
49
 
50
50
  if parent
51
51
  @parent = parent
52
- @config = merge_parent_config ? Eye::Utils::deep_clone(parent.config) : {}
52
+ if merge_parent_config
53
+ @config = Eye::Utils::deep_clone(parent.config)
54
+ parent.not_seed_options.each { |opt| @config.delete(opt) }
55
+ else
56
+ @config = {}
57
+ end
53
58
  @full_name = "#{parent.full_name}:#{@full_name}"
54
59
  else
55
60
  @config = {}
@@ -66,6 +71,10 @@ class Eye::Dsl::PureOpts
66
71
  []
67
72
  end
68
73
 
74
+ def not_seed_options
75
+ []
76
+ end
77
+
69
78
  def with_condition(cond = true, &block)
70
79
  self.instance_eval(&block) if cond && block
71
80
  end
@@ -90,6 +99,8 @@ class Eye::Dsl::PureOpts
90
99
  end
91
100
  end
92
101
 
102
+ def nop(*args, &block); end
103
+
93
104
  private
94
105
 
95
106
  def self.with_parsed_file(file_name)
data/lib/eye/group.rb CHANGED
@@ -109,7 +109,7 @@ class Eye::Group
109
109
 
110
110
  def break_chain
111
111
  info "break chain"
112
- scheduler.clear_pending_list
112
+ scheduler_clear_pending_list
113
113
  @chain_breaker = true
114
114
  end
115
115
 
data/lib/eye/http.rb CHANGED
@@ -1,3 +1,6 @@
1
+ gem 'reel', '~> 0.4.0.pre'
2
+ gem 'cuba'
3
+
1
4
  require 'reel'
2
5
 
3
6
  class Eye::Http
data/lib/eye/loader.rb CHANGED
@@ -11,13 +11,3 @@ gem 'state_machine', '< 1.2'
11
11
  gem 'activesupport', '~> 3.2.0'
12
12
  gem 'i18n'
13
13
  gem 'multi_json'
14
-
15
- # reel
16
- gem 'reel', '~> 0.4.0.pre'
17
- gem 'rack'
18
- gem 'http'
19
- gem 'http_parser.rb'
20
- gem 'certified'
21
- gem 'websocket_parser'
22
-
23
- gem 'cuba'
data/lib/eye/logger.rb CHANGED
@@ -42,11 +42,11 @@ class Eye::Logger
42
42
  attr_reader :dev, :log_level
43
43
 
44
44
  def link_logger(dev)
45
- @dev = dev ? dev.to_s.downcase : nil
45
+ @dev = dev ? dev.to_s : nil
46
46
  @dev_fd = @dev
47
47
 
48
- @dev_fd = STDOUT if @dev == 'stdout'
49
- @dev_fd = STDERR if @dev == 'stderr'
48
+ @dev_fd = STDOUT if @dev.to_s.downcase == 'stdout'
49
+ @dev_fd = STDERR if @dev.to_s.downcase == 'stderr'
50
50
 
51
51
  @inner_logger = InnerLogger.new(@dev_fd)
52
52
  @inner_logger.level = self.log_level || Logger::INFO
@@ -77,4 +77,4 @@ private
77
77
  end
78
78
  end
79
79
 
80
- end
80
+ end
@@ -53,6 +53,10 @@ module Eye::Process::Scheduler
53
53
  def scheduler_actions_list
54
54
  scheduler.list.map{|c| c[:args].first rescue nil }.compact
55
55
  end
56
+
57
+ def scheduler_clear_pending_list
58
+ scheduler.clear_pending_list
59
+ end
56
60
 
57
61
  def self.included(base)
58
62
  base.finalizer :remove_scheduler
@@ -1,4 +1,5 @@
1
1
  require 'shellwords'
2
+ require 'etc'
2
3
 
3
4
  module Eye::Process::Validate
4
5
 
@@ -18,6 +19,13 @@ module Eye::Process::Validate
18
19
 
19
20
  Shellwords.shellwords(config[:stop_command]) if config[:stop_command]
20
21
  Shellwords.shellwords(config[:restart_command]) if config[:restart_command]
22
+
23
+ Etc.getpwnam(config[:uid]) if config[:uid]
24
+ Etc.getpwnam(config[:gid]) if config[:gid]
25
+
26
+ if config[:working_dir]
27
+ raise Error, "working_dir '#{config[:working_dir]}' is invalid" unless File.directory?(config[:working_dir])
28
+ end
21
29
  end
22
30
 
23
- end
31
+ end
@@ -46,14 +46,14 @@ private
46
46
  end
47
47
 
48
48
  def start_checkers
49
- self[:checks].each{|type, cfg| start_checker(cfg) }
49
+ self[:checks].each{|name, cfg| start_checker(name, cfg) }
50
50
  end
51
51
 
52
- def start_checker(cfg)
52
+ def start_checker(name, cfg)
53
53
  subject = Eye::Checker.create(pid, cfg, logger.prefix)
54
54
 
55
55
  # ex: {:type => :memory, :every => 5.seconds, :below => 100.megabytes, :times => [3,5]}
56
- add_watcher("check_#{cfg[:type]}".to_sym, subject.every, subject, &method(:watcher_tick).to_proc)
56
+ add_watcher("check_#{name}".to_sym, subject.every, subject, &method(:watcher_tick).to_proc)
57
57
  end
58
58
 
59
59
  def watcher_tick(subject)
data/lib/eye/settings.rb CHANGED
@@ -4,7 +4,7 @@ module Eye::Settings
4
4
  module_function
5
5
 
6
6
  def dir
7
- if Process::UID.eid == 0 # root
7
+ if root?
8
8
  '/var/run/eye'
9
9
  else
10
10
  File.expand_path(File.join(home, '.eye'))
@@ -12,13 +12,17 @@ module Eye::Settings
12
12
  end
13
13
 
14
14
  def eyeconfig
15
- if Process::UID.eid == 0 # root
15
+ if root?
16
16
  '/etc/eye.conf'
17
17
  else
18
18
  File.expand_path(File.join(home, '.eyeconfig'))
19
19
  end
20
20
  end
21
21
 
22
+ def root?
23
+ Process::UID.eid == 0
24
+ end
25
+
22
26
  def home
23
27
  ENV['EYE_HOME'] || ENV['HOME']
24
28
  end
@@ -32,15 +36,23 @@ module Eye::Settings
32
36
  end
33
37
 
34
38
  def socket_path
35
- path('sock')
39
+ path(ENV['EYE_SOCK'] || "sock#{ENV['EYE_V']}")
36
40
  end
37
41
 
38
42
  def pid_path
39
- path('pid')
43
+ path(ENV['EYE_PID'] || "pid#{ENV['EYE_V']}")
40
44
  end
41
45
 
46
+ def cache_path
47
+ path("processes#{ENV['EYE_V']}.cache")
48
+ end
49
+
42
50
  def client_timeout
43
51
  5
44
52
  end
45
53
 
46
- end
54
+ def supported_setsid?
55
+ RUBY_VERSION >= '2.0'
56
+ end
57
+
58
+ end
data/lib/eye/system.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'shellwords'
2
2
  require 'pathname'
3
+ require 'etc'
3
4
 
4
5
  module Eye::System
5
6
  class << self
@@ -134,6 +135,14 @@ module Eye::System
134
135
  o.update(out: [config[:stdout], 'a']) if config[:stdout]
135
136
  o.update(err: [config[:stderr], 'a']) if config[:stderr]
136
137
  o.update(in: config[:stdin]) if config[:stdin]
138
+
139
+ if Eye::Settings.root?
140
+ o.update(uid: Etc.getpwnam(config[:uid]).uid) if config[:uid]
141
+ o.update(gid: Etc.getpwnam(config[:gid]).gid) if config[:gid]
142
+ end
143
+
144
+ o.update(umask: config[:umask]) if config[:umask]
145
+
137
146
  o
138
147
  end
139
148
 
@@ -2,7 +2,8 @@ class Eye::Utils::AliveArray
2
2
  extend Forwardable
3
3
  include Enumerable
4
4
 
5
- def_delegators :@arr, :[], :<<, :clear, :delete, :size, :empty?, :push, :flatten
5
+ def_delegators :@arr, :[], :<<, :clear, :delete, :size, :empty?, :push,
6
+ :flatten, :present?, :uniq!
6
7
 
7
8
  def initialize(arr = [])
8
9
  @arr = arr
@@ -28,4 +29,25 @@ class Eye::Utils::AliveArray
28
29
  self.class.new super
29
30
  end
30
31
 
32
+ def +(other)
33
+ if other.is_a?(Eye::Utils::AliveArray)
34
+ @arr += other.pure
35
+ elsif other.is_a?(Array)
36
+ @arr += other
37
+ else
38
+ raise "Unexpected + #{other}"
39
+ end
40
+ self
41
+ end
42
+
43
+ def ==(other)
44
+ if other.is_a?(Eye::Utils::AliveArray)
45
+ @arr == other.pure
46
+ elsif other.is_a?(Array)
47
+ @arr == other
48
+ else
49
+ raise "Unexpected == #{other}"
50
+ end
51
+ end
52
+
31
53
  end