win32-service 0.7.2 → 0.8.0
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.
- data/CHANGES +4 -0
- data/MANIFEST +2 -3
- data/README +75 -71
- data/Rakefile +7 -90
- data/doc/daemon.txt +7 -7
- data/doc/service.txt +8 -9
- data/examples/demo_daemon.rb +11 -11
- data/examples/demo_daemon_ctl.rb +3 -3
- data/examples/demo_services.rb +30 -30
- data/lib/win32/daemon.rb +345 -0
- data/lib/win32/service.rb +346 -434
- data/lib/win32/windows/constants.rb +137 -0
- data/lib/win32/windows/functions.rb +63 -0
- data/lib/win32/windows/helper.rb +41 -0
- data/lib/win32/windows/structs.rb +96 -0
- data/test/test_win32_daemon.rb +10 -13
- data/test/test_win32_service.rb +54 -48
- data/test/test_win32_service_configure.rb +19 -22
- data/test/test_win32_service_create.rb +129 -131
- data/test/test_win32_service_info.rb +8 -9
- data/test/test_win32_service_status.rb +2 -5
- data/win32-service.gemspec +5 -11
- metadata +61 -74
- data/ext/extconf.rb +0 -9
- data/ext/win32/daemon.c +0 -612
@@ -3,27 +3,24 @@
|
|
3
3
|
#
|
4
4
|
# Test suite that validates the Service.configure method.
|
5
5
|
#######################################################################
|
6
|
-
require '
|
7
|
-
gem 'test-unit'
|
8
|
-
|
6
|
+
require 'test-unit'
|
9
7
|
require 'win32/service'
|
10
|
-
require 'test/unit'
|
11
8
|
|
12
9
|
class TC_Win32_Service_Configure < Test::Unit::TestCase
|
13
10
|
def self.startup
|
14
11
|
@@service = "notepad_service"
|
15
12
|
@@command = "C:\\windows\\system32\\notepad.exe"
|
16
|
-
|
13
|
+
|
17
14
|
Win32::Service.new(
|
18
15
|
:service_name => @@service,
|
19
16
|
:binary_path_name => @@command
|
20
17
|
)
|
21
18
|
end
|
22
|
-
|
19
|
+
|
23
20
|
def config_info
|
24
21
|
Win32::Service.config_info(@@service)
|
25
22
|
end
|
26
|
-
|
23
|
+
|
27
24
|
def full_info
|
28
25
|
service = nil
|
29
26
|
Win32::Service.services{ |s|
|
@@ -34,39 +31,39 @@ class TC_Win32_Service_Configure < Test::Unit::TestCase
|
|
34
31
|
}
|
35
32
|
service
|
36
33
|
end
|
37
|
-
|
34
|
+
|
38
35
|
def service_configure(opt)
|
39
36
|
options = {:service_name => @@service}
|
40
37
|
options = options.merge(opt)
|
41
|
-
assert_nothing_raised{ Win32::Service.configure(options) }
|
38
|
+
assert_nothing_raised{ Win32::Service.configure(options) }
|
42
39
|
end
|
43
|
-
|
40
|
+
|
44
41
|
def setup
|
45
42
|
@info = Win32::Service.config_info(@@service)
|
46
43
|
end
|
47
|
-
|
44
|
+
|
48
45
|
test "configure method is defined" do
|
49
46
|
assert_respond_to(Win32::Service, :configure)
|
50
47
|
end
|
51
|
-
|
48
|
+
|
52
49
|
test "configuring the service type works as expected" do
|
53
50
|
assert_equal('own process, interactive', config_info.service_type)
|
54
|
-
service_configure(:service_type => Win32::Service::WIN32_SHARE_PROCESS)
|
51
|
+
service_configure(:service_type => Win32::Service::WIN32_SHARE_PROCESS)
|
55
52
|
assert_equal('share process', config_info.service_type)
|
56
53
|
end
|
57
|
-
|
54
|
+
|
58
55
|
test "configuring the description works as expected" do
|
59
56
|
assert_equal('', full_info.description)
|
60
|
-
service_configure(:description => 'test service')
|
57
|
+
service_configure(:description => 'test service')
|
61
58
|
assert_equal('test service', full_info.description)
|
62
59
|
end
|
63
|
-
|
60
|
+
|
64
61
|
test "configuring the start type works as expected" do
|
65
62
|
assert_equal('demand start', config_info.start_type)
|
66
63
|
service_configure(:start_type => Win32::Service::DISABLED)
|
67
|
-
assert_equal('disabled', config_info.start_type)
|
64
|
+
assert_equal('disabled', config_info.start_type)
|
68
65
|
end
|
69
|
-
|
66
|
+
|
70
67
|
test "the configure method requires one argument" do
|
71
68
|
assert_raise(ArgumentError){ Win32::Service.configure }
|
72
69
|
end
|
@@ -84,14 +81,14 @@ class TC_Win32_Service_Configure < Test::Unit::TestCase
|
|
84
81
|
Win32::Service.configure(:binary_path_name => 'notepad.exe')
|
85
82
|
}
|
86
83
|
end
|
87
|
-
|
84
|
+
|
88
85
|
def teardown
|
89
86
|
@info = nil
|
90
87
|
end
|
91
|
-
|
88
|
+
|
92
89
|
def self.shutdown
|
93
90
|
Win32::Service.delete(@@service) if Win32::Service.exists?(@@service)
|
94
91
|
@@service = nil
|
95
|
-
@@command = nil
|
96
|
-
end
|
92
|
+
@@command = nil
|
93
|
+
end
|
97
94
|
end
|
@@ -1,131 +1,129 @@
|
|
1
|
-
########################################################################
|
2
|
-
# test_win32_service_create.rb
|
3
|
-
#
|
4
|
-
# Test case for the Service.create method. This test case will create
|
5
|
-
# a dummy (notepad) service. It won't actually run of course.
|
6
|
-
########################################################################
|
7
|
-
require '
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
:
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
assert_equal('
|
96
|
-
assert_equal(
|
97
|
-
assert_equal('
|
98
|
-
assert_equal(
|
99
|
-
assert_equal('
|
100
|
-
assert_equal(
|
101
|
-
assert_equal(
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
@@
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
end
|
1
|
+
########################################################################
|
2
|
+
# test_win32_service_create.rb
|
3
|
+
#
|
4
|
+
# Test case for the Service.create method. This test case will create
|
5
|
+
# a dummy (notepad) service. It won't actually run of course.
|
6
|
+
########################################################################
|
7
|
+
require 'test-unit'
|
8
|
+
require 'win32/service'
|
9
|
+
|
10
|
+
class TC_Win32_Service_Create < Test::Unit::TestCase
|
11
|
+
def self.startup
|
12
|
+
@@service1 = "notepad_service1"
|
13
|
+
@@service2 = "notepad_service2"
|
14
|
+
@@command = "C:\\windows\\system32\\notepad.exe"
|
15
|
+
|
16
|
+
Win32::Service.new(
|
17
|
+
:service_name => @@service1,
|
18
|
+
:binary_path_name => @@command
|
19
|
+
)
|
20
|
+
|
21
|
+
Win32::Service.new(
|
22
|
+
:service_name => @@service2,
|
23
|
+
:display_name => 'Notepad Test',
|
24
|
+
:desired_access => Win32::Service::ALL_ACCESS,
|
25
|
+
:service_type => Win32::Service::WIN32_OWN_PROCESS,
|
26
|
+
:start_type => Win32::Service::DISABLED,
|
27
|
+
:error_control => Win32::Service::ERROR_IGNORE,
|
28
|
+
:binary_path_name => @@command,
|
29
|
+
:load_order_group => 'Network',
|
30
|
+
:dependencies => 'W32Time',
|
31
|
+
:description => 'Test service. Please delete me'
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def setup
|
36
|
+
@info1 = Win32::Service.config_info(@@service1)
|
37
|
+
@info2 = Win32::Service.config_info(@@service2)
|
38
|
+
end
|
39
|
+
|
40
|
+
test "constructor basic functionality" do
|
41
|
+
assert_respond_to(Win32::Service, :new)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Service.create works, but the test fails. Might be a bug in test-unit.
|
45
|
+
test "create is an alias for new" do
|
46
|
+
assert_respond_to(Win32::Service, :create)
|
47
|
+
#assert_alias_method(Win32::Service, :create, :new)
|
48
|
+
end
|
49
|
+
|
50
|
+
test "ensure services were created in startup method" do
|
51
|
+
notify "If this test fails then remaining results are meaningless."
|
52
|
+
assert_true(Win32::Service.exists?(@@service1))
|
53
|
+
assert_true(Win32::Service.exists?(@@service2))
|
54
|
+
end
|
55
|
+
|
56
|
+
test "expected service type configuration information" do
|
57
|
+
assert_equal('own process, interactive', @info1.service_type)
|
58
|
+
end
|
59
|
+
|
60
|
+
test "expected start type configuration information" do
|
61
|
+
assert_equal('demand start', @info1.start_type)
|
62
|
+
end
|
63
|
+
|
64
|
+
test "expected error control configuration information" do
|
65
|
+
assert_equal('normal', @info1.error_control)
|
66
|
+
end
|
67
|
+
|
68
|
+
test "expected binary path name configuration information" do
|
69
|
+
assert_equal(@@command, @info1.binary_path_name)
|
70
|
+
end
|
71
|
+
|
72
|
+
test "expected load order group configuration information" do
|
73
|
+
assert_equal('', @info1.load_order_group)
|
74
|
+
end
|
75
|
+
|
76
|
+
test "expected tag id configuration information" do
|
77
|
+
assert_equal(0, @info1.tag_id)
|
78
|
+
end
|
79
|
+
|
80
|
+
test "expected dependency configuration information" do
|
81
|
+
assert_equal([], @info1.dependencies)
|
82
|
+
end
|
83
|
+
|
84
|
+
test "expected service start time configuration information" do
|
85
|
+
assert_equal('LocalSystem', @info1.service_start_name)
|
86
|
+
end
|
87
|
+
|
88
|
+
test "expected display name configuration information" do
|
89
|
+
assert_equal('notepad_service1', @info1.display_name)
|
90
|
+
end
|
91
|
+
|
92
|
+
test "configuration information options are set properly for service 2" do
|
93
|
+
assert_equal('own process', @info2.service_type)
|
94
|
+
assert_equal('disabled', @info2.start_type)
|
95
|
+
assert_equal('ignore', @info2.error_control)
|
96
|
+
assert_equal(@@command, @info2.binary_path_name)
|
97
|
+
assert_equal('Network', @info2.load_order_group)
|
98
|
+
assert_equal(0, @info2.tag_id)
|
99
|
+
assert_equal(['W32Time'], @info2.dependencies)
|
100
|
+
assert_equal('LocalSystem', @info2.service_start_name)
|
101
|
+
assert_equal('Notepad Test', @info2.display_name)
|
102
|
+
end
|
103
|
+
|
104
|
+
test "at least one argument is required or an error is raised" do
|
105
|
+
assert_raise(ArgumentError){ Win32::Service.new }
|
106
|
+
end
|
107
|
+
|
108
|
+
test "passing a bogus option to the constructor will cause an error" do
|
109
|
+
assert_raise(ArgumentError){ Win32::Service.new(:bogus => 'test.exe') }
|
110
|
+
end
|
111
|
+
|
112
|
+
test "the service name must be provided or an error is raised" do
|
113
|
+
assert_raise(ArgumentError){ Win32::Service.new(:binary_path_name => 'test.exe') }
|
114
|
+
end
|
115
|
+
|
116
|
+
def teardown
|
117
|
+
@info1 = nil
|
118
|
+
@info2 = nil
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.shutdown
|
122
|
+
Win32::Service.delete(@@service1) if Win32::Service.exists?(@@service1)
|
123
|
+
Win32::Service.delete(@@service2) if Win32::Service.exists?(@@service2)
|
124
|
+
|
125
|
+
@@service1 = nil
|
126
|
+
@@service2 = nil
|
127
|
+
@@command = nil
|
128
|
+
end
|
129
|
+
end
|
@@ -3,19 +3,17 @@
|
|
3
3
|
#
|
4
4
|
# Test case for the Struct::ServiceInfo structure.
|
5
5
|
########################################################################
|
6
|
-
require '
|
7
|
-
gem 'test-unit'
|
8
|
-
|
6
|
+
require 'test-unit'
|
9
7
|
require 'win32/service'
|
10
|
-
require 'test/unit'
|
11
8
|
|
12
9
|
class TC_Win32_ServiceInfo_Struct < Test::Unit::TestCase
|
13
10
|
def self.startup
|
14
|
-
@@services = Win32::Service.services
|
11
|
+
@@services = Win32::Service.services
|
15
12
|
end
|
16
|
-
|
13
|
+
|
17
14
|
def setup
|
18
|
-
@
|
15
|
+
@service_name = "Dhcp"
|
16
|
+
@service_info = @@services.find{ |s| s.service_name == @service_name }
|
19
17
|
|
20
18
|
@error_controls = [
|
21
19
|
'critical',
|
@@ -59,7 +57,7 @@ class TC_Win32_ServiceInfo_Struct < Test::Unit::TestCase
|
|
59
57
|
nil
|
60
58
|
]
|
61
59
|
|
62
|
-
@controls = [
|
60
|
+
@controls = [
|
63
61
|
'netbind change',
|
64
62
|
'param change',
|
65
63
|
'pause continue',
|
@@ -176,8 +174,9 @@ class TC_Win32_ServiceInfo_Struct < Test::Unit::TestCase
|
|
176
174
|
@types = nil
|
177
175
|
@states = nil
|
178
176
|
@controls = nil
|
177
|
+
@service_name = nil
|
179
178
|
end
|
180
|
-
|
179
|
+
|
181
180
|
def self.shutdown
|
182
181
|
@@services = nil
|
183
182
|
end
|
@@ -3,11 +3,8 @@
|
|
3
3
|
#
|
4
4
|
# Test case for the Struct::ServiceStatus struct.
|
5
5
|
########################################################################
|
6
|
-
require '
|
7
|
-
gem 'test-unit'
|
8
|
-
|
6
|
+
require 'test-unit'
|
9
7
|
require 'win32/service'
|
10
|
-
require 'test/unit'
|
11
8
|
|
12
9
|
class TC_Win32_ServiceStatus_Struct < Test::Unit::TestCase
|
13
10
|
def setup
|
@@ -39,7 +36,7 @@ class TC_Win32_ServiceStatus_Struct < Test::Unit::TestCase
|
|
39
36
|
nil
|
40
37
|
]
|
41
38
|
|
42
|
-
@controls = [
|
39
|
+
@controls = [
|
43
40
|
'netbind change',
|
44
41
|
'param change',
|
45
42
|
'pause continue',
|
data/win32-service.gemspec
CHANGED
@@ -2,15 +2,13 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'win32-service'
|
5
|
-
spec.version = '0.
|
5
|
+
spec.version = '0.8.0'
|
6
6
|
spec.authors = ['Daniel J. Berger', 'Park Heesob']
|
7
7
|
spec.license = 'Artistic 2.0'
|
8
8
|
spec.email = 'djberg96@gmail.com'
|
9
|
-
spec.homepage = 'http://
|
10
|
-
spec.platform = Gem::Platform::RUBY
|
9
|
+
spec.homepage = 'http://github.com/djberg96/win32-service'
|
11
10
|
spec.summary = 'An interface for MS Windows services'
|
12
11
|
spec.test_files = Dir['test/test*.rb']
|
13
|
-
spec.extensions = ['ext/extconf.rb']
|
14
12
|
|
15
13
|
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
16
14
|
|
@@ -19,15 +17,11 @@ Gem::Specification.new do |spec|
|
|
19
17
|
'README',
|
20
18
|
'MANIFEST',
|
21
19
|
'doc/service.txt',
|
22
|
-
'doc/daemon.txt'
|
23
|
-
'ext/win32/daemon.c'
|
20
|
+
'doc/daemon.txt'
|
24
21
|
]
|
25
22
|
|
26
|
-
spec.
|
27
|
-
spec.
|
28
|
-
|
29
|
-
spec.add_dependency('windows-pr', '>= 1.0.8')
|
30
|
-
spec.add_development_dependency('test-unit', '>= 2.1.0')
|
23
|
+
spec.add_dependency('ffi')
|
24
|
+
spec.add_development_dependency('test-unit', '>= 2.4.0')
|
31
25
|
|
32
26
|
spec.description = <<-EOF
|
33
27
|
The win32-service library provides a Ruby interface to services on
|