svutil 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,26 +1,27 @@
1
1
  = svutil
2
2
 
3
- * FIX (url)
3
+ * http://svutil.rubyforge.org
4
4
 
5
5
  == DESCRIPTION:
6
6
 
7
- FIX (describe your package)
7
+ A simple managed process builder for Ruby projects
8
8
 
9
9
  == FEATURES/PROBLEMS:
10
10
 
11
- * FIX (list of features or problems)
11
+ * TODO
12
12
 
13
13
  == SYNOPSIS:
14
14
 
15
- FIX (code sample of usage)
15
+ service = ProcessManager.new(Server)
16
+ service.start
16
17
 
17
18
  == REQUIREMENTS:
18
19
 
19
- * FIX (list of requirements)
20
+ * None
20
21
 
21
22
  == INSTALL:
22
23
 
23
- * FIX (sudo gem install, anything else)
24
+ sudo gem install
24
25
 
25
26
  == LICENSE:
26
27
 
@@ -45,4 +46,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
46
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
47
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
48
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,16 +1,15 @@
1
- %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
1
+ %w[rubygems rake rake/clean hoe fileutils newgem rubigen].each { |f| require f }
2
2
  require File.dirname(__FILE__) + '/lib/svutil'
3
3
 
4
4
  # Generate all the Rake tasks
5
5
  # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
- $hoe = Hoe.new('svutil', SVUtil::VERSION) do |p|
7
- p.developer('FIXME full name', 'FIXME email')
6
+ $hoe = Hoe.spec('svutil') do |p|
7
+ p.version = SVUtil::VERSION
8
+ p.developer('Daniel Draper', 'daniel@netfox.com')
9
+ p.summary = "Simple Process Builder for Ruby"
8
10
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
11
  p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
12
  p.rubyforge_name = p.name # TODO this is default value
11
- # p.extra_deps = [
12
- # ['activesupport','>= 2.0.2'],
13
- # ]
14
13
  p.extra_dev_deps = [
15
14
  ['newgem', ">= #{::Newgem::VERSION}"]
16
15
  ]
@@ -6,5 +6,5 @@ require 'svutil/log'
6
6
  require 'svutil/process_manager'
7
7
 
8
8
  module SVUtil
9
- VERSION = '0.0.2'
9
+ VERSION = '0.0.3'
10
10
  end
@@ -13,69 +13,79 @@ module SVUtil
13
13
  attr_writer :config_file
14
14
 
15
15
  def config_class
16
- subclasses_of(self).first || self
16
+ subclasses_of(self).first || self
17
17
  end
18
18
 
19
19
  def config_file
20
- @config_file || 'settings'
20
+ @config_file || 'settings'
21
21
  end
22
22
 
23
23
  def load_and_parse
24
- process_options
25
- load_config_file
26
- apply_all
27
- validate
24
+ process_options
25
+ load_config_file
26
+ apply_all
27
+ validate
28
28
  end
29
29
 
30
30
  def set(name, value)
31
- @temp_hash ||= {}
32
- @temp_hash[name.to_s] = value
31
+ @temp_hash ||= {}
32
+ @temp_hash[name.to_s] = value
33
33
  end
34
34
 
35
35
  def apply(name, value)
36
- @hash ||= {}
37
- @hash[name.to_s] = value
36
+ @hash ||= {}
37
+ @hash[name.to_s] = value
38
38
  end
39
39
 
40
40
  def apply_all
41
- @hash ||= {}
42
- @hash.merge!(@temp_hash) if @temp_hash
41
+ @hash ||= {}
42
+ @hash.merge!(@temp_hash) if @temp_hash
43
43
  end
44
44
 
45
45
  def method_missing(method_id, *args)
46
- return nil unless @hash
47
- @hash[method_id.to_s]
46
+ return nil unless @hash
47
+ @hash[method_id.to_s]
48
48
  end
49
49
 
50
50
  def validate
51
- # TODO: Check file perms
51
+ # TODO: Check file perms
52
52
  if (pid_file.nil? or pid_file.empty? or File.directory?(pid_file))
53
53
  STDERR.puts "PID file must be a writable file"
54
54
  exit 1
55
55
  end
56
56
  end
57
+
58
+ def process_options
59
+ parse_options
60
+ end
57
61
 
58
62
  def parse_options
59
63
  OptionParser.new do |opts|
60
64
  opts.on("-f", "--config [filename]", "Config file to use (default 'settings')") do |filename|
61
65
  config.config_file = filename
62
- end
63
- yield opts
64
- end.parse!
66
+ end
67
+ opts.on("-d", "--daemon", "Run in the background as a daemon") do
68
+ config.set(:daemon, true)
69
+ end
70
+ opts.on("-l", "--debug-log [log-file]", "Debug Log File") do |log|
71
+ config.set(log_file, log)
72
+ end
73
+ yield opts if block_given?
74
+ end.parse!
65
75
  end
66
76
 
67
77
  private
68
78
  def load_config_file
69
- contents = ""
70
- File.open(config_file, "r") { |file| contents << file.read }
71
- contents.split("\n").each_with_index do |line, index|
72
- pair = line.split("=")
79
+ contents = ""
80
+ File.open(config_file, "r") { |file| contents << file.read }
81
+ contents.split("\n").each_with_index do |line, index|
82
+ pair = line.split("=")
73
83
  if pair.size != 2
74
- STDERR.puts "Invalid config file '#{config_file}'. Syntax error at line #{index + 1}"
75
- exit 1
76
- end
77
- config_class.apply(pair[0].strip, pair[1].strip)
78
- end
84
+ STDERR.puts "Invalid config file '#{config_file}'. Syntax error at line #{index + 1}"
85
+ exit 1
86
+ end
87
+ config_class.apply(pair[0].strip, pair[1].strip)
88
+ end
79
89
  end
80
90
 
81
91
  def subclasses_of(*superclasses) #:nodoc:
@@ -83,8 +93,8 @@ module SVUtil
83
93
  superclasses.each do |sup|
84
94
  ObjectSpace.each_object(Class) do |k|
85
95
  if superclasses.any? { |superclass| k < superclass } &&
86
- (k.name.nil? || k.name.empty? || eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id"))
87
- subclasses << k
96
+ (k.name.nil? || k.name.empty? || eval("defined?(::#{k}) && ::#{k}.object_id == k.object_id"))
97
+ subclasses << k
88
98
  end
89
99
  end
90
100
  subclasses.uniq!
@@ -2,13 +2,13 @@ module SVUtil
2
2
  class Log
3
3
  class << self
4
4
  %w(info warning error).each do |level|
5
- define_method(level) do |arg|
6
- log(level, arg)
7
- end
5
+ define_method(level) do |arg|
6
+ log(level, arg)
7
+ end
8
8
  end
9
9
 
10
10
  def log(level, arg)
11
- STDOUT.puts "#{Time.now}: (#{level}) #{arg}"
11
+ STDOUT.puts "#{Time.now}: (#{level}) #{arg}"
12
12
  end
13
13
  end
14
14
  end
@@ -4,8 +4,8 @@ module SVUtil
4
4
  Signal.trap("INT") { shutdown }
5
5
  Signal.trap("TERM") { shutdown }
6
6
  if running?
7
- STDERR.puts "There is already a '#{$0}' process running"
8
- exit 1
7
+ STDERR.puts "There is already a '#{$0}' process running"
8
+ exit 1
9
9
  end
10
10
  daemonize if config.daemon
11
11
  write_pid_file
@@ -31,22 +31,22 @@ module SVUtil
31
31
  end
32
32
 
33
33
  def running?
34
- pid_file = config.pid_file
35
- return false unless pid_file
36
- File.exist?(pid_file)
34
+ pid_file = config.pid_file
35
+ return false unless pid_file
36
+ File.exist?(pid_file)
37
37
  end
38
38
 
39
39
  def write_pid_file
40
- pid_file = config.pid_file
41
- return unless pid_file
42
- File.open(pid_file, "w") { |f| f.write(Process.pid) }
43
- File.chmod(0644, pid_file)
40
+ pid_file = config.pid_file
41
+ return unless pid_file
42
+ File.open(pid_file, "w") { |f| f.write(Process.pid) }
43
+ File.chmod(0644, pid_file)
44
44
  end
45
45
 
46
46
  def remove_pid_file
47
- pid_file = config.pid_file
48
- return unless pid_file
49
- File.unlink(pid_file) if File.exists?(pid_file)
47
+ pid_file = config.pid_file
48
+ return unless pid_file
49
+ File.unlink(pid_file) if File.exists?(pid_file)
50
50
  end
51
51
 
52
52
  def daemonize
@@ -55,20 +55,19 @@ module SVUtil
55
55
  end
56
56
 
57
57
  def redirect_io
58
- begin; STDIN.reopen('/dev/null'); rescue Exception; end
59
- if config.log_file
60
- begin
58
+ begin; STDIN.reopen('/dev/null'); rescue Exception; end
59
+ if config.log_file
60
+ begin
61
61
  STDOUT.reopen(config.log_file, "a")
62
- STDOUT.sync = true
63
- rescue Exception
62
+ STDOUT.sync = true
63
+ rescue Exception
64
64
  begin; STDOUT.reopen('/dev/null'); rescue Exception; end
65
- end
66
- else
67
- begin; STDOUT.reopen('/dev/null'); rescue Exception; end
68
- end
69
-
70
- begin; STDERR.reopen(STDOUT); rescue Exception; end
71
- STDERR.sync = true
65
+ end
66
+ else
67
+ begin; STDOUT.reopen('/dev/null'); rescue Exception; end
68
+ end
69
+ begin; STDERR.reopen(STDOUT); rescue Exception; end
70
+ STDERR.sync = true
72
71
  end
73
72
  end
74
73
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svutil
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
- - FIXME full name
7
+ - Daniel Draper
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-29 00:00:00 +09:30
12
+ date: 2009-09-22 00:00:00 +09:30
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.3.0
23
+ version: 1.5.2
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
@@ -30,11 +30,11 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.8.0
33
+ version: 2.3.3
34
34
  version:
35
- description: FIX (describe your package)
35
+ description: ""
36
36
  email:
37
- - FIXME email
37
+ - daniel@netfox.com
38
38
  executables: []
39
39
 
40
40
  extensions: []
@@ -43,7 +43,6 @@ extra_rdoc_files:
43
43
  - History.txt
44
44
  - Manifest.txt
45
45
  - PostInstall.txt
46
- - README.rdoc
47
46
  files:
48
47
  - History.txt
49
48
  - Manifest.txt
@@ -57,11 +56,13 @@ files:
57
56
  - test/test_helper.rb
58
57
  - test/test_svutil.rb
59
58
  has_rdoc: true
60
- homepage: FIX (url)
59
+ homepage:
60
+ licenses: []
61
+
61
62
  post_install_message: PostInstall.txt
62
63
  rdoc_options:
63
64
  - --main
64
- - README.rdoc
65
+ - README.txt
65
66
  require_paths:
66
67
  - lib
67
68
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -79,10 +80,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
79
80
  requirements: []
80
81
 
81
82
  rubyforge_project: svutil
82
- rubygems_version: 1.3.1
83
+ rubygems_version: 1.3.3
83
84
  signing_key:
84
- specification_version: 2
85
- summary: FIX (describe your package)
85
+ specification_version: 3
86
+ summary: Simple Process Builder for Ruby
86
87
  test_files:
87
- - test/test_helper.rb
88
88
  - test/test_svutil.rb
89
+ - test/test_helper.rb