freyr 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.3.6
@@ -85,7 +85,7 @@ module Freyr
85
85
 
86
86
  proc = ProcessInfo[pid]
87
87
 
88
- str << " CPU: #{proc.pcpu}% - MEM: #{proc.mem_in_mb}mb" if proc
88
+ str << " CPU: #{proc.pcpu}% - MEM: #{proc.mem_in_mb.to_i}mb" if proc
89
89
  # rescue => e
90
90
  end
91
91
  end
data/lib/freyr/command.rb CHANGED
@@ -13,12 +13,6 @@ module Freyr
13
13
  Dir.mkdir(FREYR_PIDS)
14
14
  end
15
15
 
16
- ServiceInfo::ATTRS.each do |meth|
17
- define_method(meth) do |*args|
18
- @service.__send__(meth,*args) if @service
19
- end
20
- end
21
-
22
16
  attr_reader :command, :name, :service
23
17
 
24
18
  def initialize(name, command=nil, args = {})
@@ -263,6 +257,16 @@ module Freyr
263
257
  end
264
258
  end
265
259
 
260
+
261
+ class << self
262
+ def add_service_method *methods
263
+ methods.each do |meth|
264
+ define_method(meth) do |*args|
265
+ @service.__send__(meth,*args) if @service
266
+ end
267
+ end
268
+ end
269
+ end
266
270
  end
267
271
 
268
272
  class AdminRequired < Errno::EACCES; end
@@ -19,8 +19,14 @@ module Freyr
19
19
  info
20
20
  end
21
21
 
22
+ def port
23
+ `lsof -p #{pid} -P | egrep TCP.+LISTEN`.match(/\*:(\d+)/)[1].to_i
24
+ rescue
25
+ nil
26
+ end
27
+
22
28
  def mem_in_mb
23
- @rss/1024
29
+ @rss/1024.0
24
30
  end
25
31
 
26
32
  class << self
data/lib/freyr/service.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  module Freyr
2
2
  class Service
3
3
  extend Forwardable
4
+ class << self
5
+ def add_service_method *methods
6
+ def_delegators :@service_info, *methods
7
+ end
8
+ end
4
9
 
5
10
  attr_reader :service_info, :command
6
11
 
@@ -9,8 +14,7 @@ module Freyr
9
14
  @command = Command.new(self)
10
15
  end
11
16
 
12
- def_delegators :@service_info, *ServiceInfo::ATTRS
13
- def_delegator :@service_info, :start, :start_command
17
+ add_service_method :start, :start_command
14
18
 
15
19
  def env
16
20
  service_info.env || {}
@@ -93,7 +97,7 @@ module Freyr
93
97
 
94
98
  services = ServiceInfo.from_file(f).collect do |ser|
95
99
  raise 'Cannot have two things of the same name' if selectors.include?(ser.name)
96
- names << ser.name
100
+ names |= [ser.name]
97
101
  @all_groups |= ser.groups
98
102
  new(ser)
99
103
  end
@@ -2,9 +2,20 @@ module Freyr
2
2
  class ServiceInfo
3
3
  attr_reader :groups
4
4
 
5
- ATTRS = [:name,:dir,:log_cmd,:log,:err_log_cmd,:err_log,:umask,
6
- :uid,:gid,:chroot,:proc_match,:restart,:stop,:stop_sig,
7
- :restart_sig,:sudo,:groups,:ping,:also,:dependencies,:read_log]
5
+ class << self
6
+ def add_service_method *methods
7
+ Service.send :add_service_method, *methods
8
+ Command.send :add_service_method, *methods
9
+ methods.each do |method|
10
+ ATTRS << methods
11
+ end
12
+ end
13
+ end
14
+
15
+ ATTRS = []
16
+ add_service_method :name,:dir,:log_cmd,:log,:err_log_cmd,:err_log,:umask,
17
+ :uid,:gid,:chroot,:proc_match,:restart,:stop,:stop_sig,
18
+ :restart_sig,:sudo,:groups,:ping,:also,:dependencies,:read_log
8
19
 
9
20
  def initialize(name=nil, args={}, &block)
10
21
  @groups = []
@@ -36,17 +47,18 @@ module Freyr
36
47
  @also |= val
37
48
  end
38
49
 
39
- MODIFIERS = {
40
- :start => :_sudo_checker,
41
- :restart => :_sudo_checker,
42
- :stop => :_sudo_checker
43
- }
50
+ MODIFIERS = Hash.new {|h,k| h[k] = []}
51
+ MODIFIERS[:start] << :_sudo_checker
52
+ MODIFIERS[:stop] << :_sudo_checker
53
+ MODIFIERS[:restart] << :_sudo_checker
44
54
 
45
55
  def method_missing key, val=nil
46
56
  key = key.to_s.gsub(/\=$/,'').to_sym
47
57
 
48
58
  if val
49
- val = send(MODIFIERS[key],val) if MODIFIERS[key]
59
+ MODIFIERS[key].each do |modifier|
60
+ val = send(modifier,val)
61
+ end
50
62
  instance_variable_set("@#{key}", val)
51
63
  else
52
64
  instance_variable_get("@#{key}")
data/lib/freyr.rb CHANGED
@@ -4,6 +4,6 @@ module Freyr
4
4
 
5
5
  end
6
6
 
7
- %w{version service_info service_group service command pinger process_info}.each do |f|
7
+ %w{version service_group service command service_info pinger process_info}.each do |f|
8
8
  require File.expand_path(File.dirname(__FILE__)+"/freyr/#{f}.rb")
9
9
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: freyr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 5
10
- version: 0.3.5
9
+ - 6
10
+ version: 0.3.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tal Atlas
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-06-15 00:00:00 -04:00
18
+ date: 2011-07-20 00:00:00 -04:00
19
19
  default_executable: freyr
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency