srvany_manager 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -13,14 +13,15 @@ PROJ.name = 'srvany_manager'
13
13
  PROJ.authors = 'James Tucker'
14
14
  PROJ.email = 'raggi@rubyforge.org'
15
15
  PROJ.url = 'http://github.com/raggi/srvany_manager'
16
- PROJ.rubyforge.name = 'libraggi'
16
+ PROJ.rubyforge.name = 'raggi'
17
17
  PROJ.version = SrvanyManager.version
18
+ PROJ.gem.dependencies = %(win32-service) # TODO where does win32/registry come from?
18
19
 
19
20
  PROJ.exclude = %w(tmp$ bak$ ~$ CVS \.git \.hg \.svn ^pkg ^doc \.DS_Store
20
21
  \.cvs \.svn \.hgignore \.gitignore \.dotest \.swp$ ~$)
21
22
 
22
23
  namespace :gem do
23
- file 'srvany_manager.gemspec' => `git ls-files`.split do |t|
24
+ file 'srvany_manager.gemspec' => (`git ls-files`.split - ['srvany_manager.gemspec']) do |t|
24
25
  open(t.name, 'w') { |f| f.write PROJ.gem._spec.to_ruby }
25
26
  end
26
27
  task :spec => 'srvany_manager.gemspec'
@@ -1,14 +1,26 @@
1
1
  class SrvanyManager
2
2
 
3
- Version = VERSION = '0.1.0'
3
+ Version = VERSION = '0.1.1'
4
4
  def self.version
5
5
  Version
6
6
  end
7
7
 
8
+ def self.load_dependencies
9
+ once = false
10
+ require 'win32/service'
11
+ require 'win32/registry'
12
+ rescue LoadError => e
13
+ raise e if once
14
+ require 'rubygems'
15
+ once = true
16
+ retry
17
+ end
18
+
8
19
  # Construct a new service manager, just sets up a name_key, which is used
9
20
  # as a leading string to the name of all services managed by the instance.
10
21
  # srv_any_path must be a full path to srvany.exe.
11
22
  def initialize(name_key = 'SRVANY_', srv_any_path = "#{ENV['ProgramFiles']}\\Windows Resource Kits\\Tools\\srvany.exe")
23
+ self.class.load_dependencies
12
24
  @name_key = name_key
13
25
  @srv_any_path = srv_any_path
14
26
  end
@@ -23,55 +35,55 @@ class SrvanyManager
23
35
  :service_type => Win32::Service::WIN32_OWN_PROCESS,
24
36
  :start_type => Win32::Service::DEMAND_START,
25
37
  :error_control => Win32::Service::ERROR_NORMAL
26
- }.merge(options)
27
- name = @name_key + name.to_s
28
- options = defaults.merge(
38
+ }.merge(options)
39
+ name = @name_key + name.to_s
40
+ options = defaults.merge(
29
41
  :display_name => name,
30
42
  :description => description || name,
31
43
  :binary_path_name => @srv_any_path
32
- )
33
- Win32::Service.create(name, nil, options)
34
- # `#{@ins_srv_path} #{name} "#{@srv_any_path}"`
35
- registry(name) do |reg|
36
- reg.create('Parameters') do |params|
37
- params.write_i("Start", 3)
38
- params.write_s("Application", command)
39
- params.write_s("AppParameters", args)
44
+ )
45
+ Win32::Service.create(name, nil, options)
46
+ # `#{@ins_srv_path} #{name} "#{@srv_any_path}"`
47
+ registry(name) do |reg|
48
+ reg.create('Parameters') do |params|
49
+ params.write_i("Start", 3)
50
+ params.write_s("Application", command)
51
+ params.write_s("AppParameters", args)
52
+ end
40
53
  end
41
54
  end
42
- end
43
-
44
- # Mark a service for deletion (note, does not terminate the service)
45
- def delete(name)
46
- Win32::Service.delete(@name_key + name.to_s)
47
- end
48
55
 
49
- def start(name)
50
- Win32::Service.start(@name_key + name.to_s)
51
- end
56
+ # Mark a service for deletion (note, does not terminate the service)
57
+ def delete(name)
58
+ Win32::Service.delete(@name_key + name.to_s)
59
+ end
52
60
 
53
- def stop(name)
54
- Win32::Service.stop(@name_key + name.to_s)
55
- end
61
+ def start(name)
62
+ Win32::Service.start(@name_key + name.to_s)
63
+ end
56
64
 
57
- # Returns an array of tuples of name and description
58
- def list
59
- services = Win32::Service.services.select do |svc|
60
- # TODO in future, 1.8.7, can use start_with?
61
- svc.display_name[0,@name_key.size] == @name_key
65
+ def stop(name)
66
+ Win32::Service.stop(@name_key + name.to_s)
62
67
  end
63
- services.map do |svc_info|
64
- name = svc_info.display_name
65
- [name.slice(@name_key.size, name.size), svc_info.description]
68
+
69
+ # Returns an array of tuples of name and description
70
+ def list
71
+ services = Win32::Service.services.select do |svc|
72
+ # TODO in future, 1.8.7, can use start_with?
73
+ svc.display_name[0,@name_key.size] == @name_key
74
+ end
75
+ services.map do |svc_info|
76
+ name = svc_info.display_name
77
+ [name.slice(@name_key.size, name.size), svc_info.description]
78
+ end
66
79
  end
67
- end
68
80
 
69
- private
70
- def registry(name, &block)
71
- Win32::Registry::HKEY_LOCAL_MACHINE.open(
81
+ private
82
+ def registry(name, &block)
83
+ Win32::Registry::HKEY_LOCAL_MACHINE.open(
72
84
  "SYSTEM\\CurrentControlSet\\Services",
73
85
  Win32::Registry::KEY_WRITE | Win32::Registry::KEY_READ
74
- ).open(name, &block)
75
- end
86
+ ).open(name, &block)
87
+ end
76
88
 
77
- end
89
+ end
data/spec/helper.rb CHANGED
@@ -15,3 +15,4 @@ Bacon.summary_on_exit
15
15
  require File.expand_path(
16
16
  File.join(File.dirname(__FILE__), %w[.. lib srvany_manager]))
17
17
 
18
+ def SrvanyManager.load_dependencies; end
data/tasks/git.rake CHANGED
@@ -34,7 +34,7 @@ namespace :git do
34
34
 
35
35
  end # namespace :git
36
36
 
37
- task 'gem:release' => 'git:create_tag'
37
+ # task 'gem:release' => 'git:create_tag'
38
38
 
39
39
  end # if HAVE_GIT
40
40
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: srvany_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Tucker
@@ -11,8 +11,17 @@ cert_chain: []
11
11
 
12
12
  date: 2008-12-20 00:00:00 +00:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: win32-service
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
16
25
  description: A quick and simple manager for running programs as services on win32. Makes use of / requires the SRVANY.exe from the Windows Resource Kit.
17
26
  email: raggi@rubyforge.org
18
27
  executables: []
@@ -65,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
74
  version:
66
75
  requirements: []
67
76
 
68
- rubyforge_project: libraggi
77
+ rubyforge_project: raggi
69
78
  rubygems_version: 1.3.1
70
79
  signing_key:
71
80
  specification_version: 2