win32-service 0.8.10 → 1.0.1
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.
- checksums.yaml +5 -5
- data/{CHANGES → CHANGELOG.md} +347 -336
- data/Gemfile +5 -0
- data/MANIFEST +24 -24
- data/README.md +75 -0
- data/Rakefile +83 -98
- data/VERSION +1 -0
- data/appveyor.yml +48 -48
- data/doc/daemon.txt +157 -157
- data/doc/service.txt +363 -363
- data/examples/demo_daemon.rb +96 -96
- data/examples/demo_daemon_ctl.rb +123 -123
- data/examples/demo_services.rb +30 -30
- data/lib/win32-daemon.rb +1 -1
- data/lib/win32-service.rb +1 -1
- data/lib/win32/daemon.rb +361 -361
- data/lib/win32/service.rb +1575 -1577
- data/lib/win32/windows/constants.rb +143 -143
- data/lib/win32/windows/functions.rb +75 -75
- data/lib/win32/windows/structs.rb +135 -135
- data/lib/win32/windows/version.rb +6 -0
- data/test/test_win32_daemon.rb +58 -58
- data/test/test_win32_service.rb +468 -468
- data/test/test_win32_service_configure.rb +110 -110
- data/test/test_win32_service_create.rb +153 -153
- data/test/test_win32_service_info.rb +189 -189
- data/test/test_win32_service_status.rb +110 -110
- data/win32-service.gemspec +41 -39
- metadata +19 -46
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README +0 -71
- data/certs/djberg96_pub.pem +0 -21
- metadata.gz.sig +0 -0
data/Gemfile
ADDED
data/MANIFEST
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
* MANIFEST
|
2
|
-
* CHANGES
|
3
|
-
* README
|
4
|
-
* Rakefile
|
5
|
-
* win32-service.gemspec
|
6
|
-
* certs/djberg96_pub.pem
|
7
|
-
* doc/daemon.txt
|
8
|
-
* doc/service.txt
|
9
|
-
* examples/demo_daemon.rb
|
10
|
-
* examples/demo_daemon_ctl.rb
|
11
|
-
* examples/demo_services.rb
|
12
|
-
* lib/win32-daemon.rb
|
13
|
-
* lib/win32-service.rb
|
14
|
-
* lib/win32/service.rb
|
15
|
-
* lib/win32/daemon.rb
|
16
|
-
* lib/win32/windows/constants.rb
|
17
|
-
* lib/win32/windows/functions.rb
|
18
|
-
* lib/win32/windows/structs.rb
|
19
|
-
* test/test_win32_daemon.rb
|
20
|
-
* test/test_win32_service_configure.rb
|
21
|
-
* test/test_win32_service_create.rb
|
22
|
-
* test/test_win32_service_info.rb
|
23
|
-
* test/test_win32_service_status.rb
|
24
|
-
* test/test_win32_service.rb
|
1
|
+
* MANIFEST
|
2
|
+
* CHANGES
|
3
|
+
* README
|
4
|
+
* Rakefile
|
5
|
+
* win32-service.gemspec
|
6
|
+
* certs/djberg96_pub.pem
|
7
|
+
* doc/daemon.txt
|
8
|
+
* doc/service.txt
|
9
|
+
* examples/demo_daemon.rb
|
10
|
+
* examples/demo_daemon_ctl.rb
|
11
|
+
* examples/demo_services.rb
|
12
|
+
* lib/win32-daemon.rb
|
13
|
+
* lib/win32-service.rb
|
14
|
+
* lib/win32/service.rb
|
15
|
+
* lib/win32/daemon.rb
|
16
|
+
* lib/win32/windows/constants.rb
|
17
|
+
* lib/win32/windows/functions.rb
|
18
|
+
* lib/win32/windows/structs.rb
|
19
|
+
* test/test_win32_daemon.rb
|
20
|
+
* test/test_win32_service_configure.rb
|
21
|
+
* test/test_win32_service_create.rb
|
22
|
+
* test/test_win32_service_info.rb
|
23
|
+
* test/test_win32_service_status.rb
|
24
|
+
* test/test_win32_service.rb
|
data/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# win32-service
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/win32-service)
|
4
|
+
|
5
|
+
The win32-service library allows you to control or create MS Windows services.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
gem install win32-service
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
require 'win32/service'
|
15
|
+
|
16
|
+
# Iterate over the available services
|
17
|
+
Win32::Service.services do |service|
|
18
|
+
p service
|
19
|
+
end
|
20
|
+
```
|
21
|
+
|
22
|
+
## More Documentation
|
23
|
+
|
24
|
+
Please see the documentation in the 'doc' directory, or the gem documentation that was installed when you installed this library as a gem.
|
25
|
+
|
26
|
+
## Known Issues
|
27
|
+
|
28
|
+
### Problem:
|
29
|
+
|
30
|
+
Service.delete causes "Unable to delete: The specified service has been marked for deletion."
|
31
|
+
|
32
|
+
### Troubleshooting:
|
33
|
+
|
34
|
+
This can be caused by one of two things. Either you attempted to delete a running service without stopping it first, or you have the Services Administrative Tool (GUI) open. In the former case, the solution is to first stop the service if it's running. In the latter, close the Services GUI admin tool before deleting.
|
35
|
+
|
36
|
+
### Problem:
|
37
|
+
|
38
|
+
Service.start causes, "The service did not respond to the start or control request in a timely fashion."
|
39
|
+
|
40
|
+
### Troubleshooting:
|
41
|
+
|
42
|
+
The best way to debug your services is to wrap your entire Daemon subclass in a begin/end block and send error messages to a file. That should give a good clue as to the nature of the problem. The most probable culprits are:
|
43
|
+
|
44
|
+
- You forgot to require 'win32/daemon' in your Daemon code.
|
45
|
+
|
46
|
+
- You've tried to require a library that's not in your $LOAD_PATH. Make sure that your require statements are inside the begin/rescue block so that you can easily find those mistakes.
|
47
|
+
|
48
|
+
- Your have a bad binary path name. Be sure to use an absolute path name for the binary path name, including the full path to the Ruby interpreter, e.g. 'c:\ruby\bin\ruby' instead of just 'ruby'.
|
49
|
+
|
50
|
+
- You've got a syntax error in your code somewhere.
|
51
|
+
|
52
|
+
## See Also
|
53
|
+
|
54
|
+
ruby-wmi
|
55
|
+
|
56
|
+
## Future Plans
|
57
|
+
|
58
|
+
Add service_session_change hook
|
59
|
+
|
60
|
+
## Copyright
|
61
|
+
|
62
|
+
(C) 2003-2018, Daniel J. Berger, All Rights Reserved
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
Artistic 2.0
|
67
|
+
|
68
|
+
## Warranty
|
69
|
+
|
70
|
+
This package is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.
|
71
|
+
|
72
|
+
## Authors
|
73
|
+
|
74
|
+
- Daniel J. Berger
|
75
|
+
- Park Heesob
|
data/Rakefile
CHANGED
@@ -1,98 +1,83 @@
|
|
1
|
-
require
|
2
|
-
require 'rake
|
3
|
-
require 'rake/
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
'**/*.
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
desc
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
namespace '
|
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
|
-
t.warning = true
|
85
|
-
t.test_files = FileList['test/test_win32_service_status.rb']
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
task :all do
|
90
|
-
Rake.application[:clean].execute
|
91
|
-
end
|
92
|
-
|
93
|
-
task :daemon do
|
94
|
-
Rake.application[:clean].execute
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
task :default => 'test:all'
|
1
|
+
require "rubygems"
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
require 'rbconfig'
|
6
|
+
include RbConfig
|
7
|
+
|
8
|
+
CLEAN.include(
|
9
|
+
'**/*.gem', # Gem files
|
10
|
+
'**/*.rbc' # Rubinius
|
11
|
+
)
|
12
|
+
|
13
|
+
namespace :example do
|
14
|
+
desc "Run the services example program."
|
15
|
+
task :services do
|
16
|
+
sh "ruby -Ilib examples/demo_services.rb"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
namespace 'test' do
|
21
|
+
desc 'Run all tests for the win32-service library'
|
22
|
+
Rake::TestTask.new('all') do |t|
|
23
|
+
t.verbose = true
|
24
|
+
t.warning = true
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'Run the tests for the Win32::Daemon class'
|
28
|
+
Rake::TestTask.new('daemon') do |t|
|
29
|
+
task :daemon
|
30
|
+
t.verbose = true
|
31
|
+
t.warning = true
|
32
|
+
t.test_files = FileList['test/test_win32_daemon.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
namespace 'service' do
|
36
|
+
desc 'Run the tests for the Win32::Service class'
|
37
|
+
Rake::TestTask.new('all') do |t|
|
38
|
+
t.verbose = true
|
39
|
+
t.warning = true
|
40
|
+
t.test_files = FileList['test/test_win32_service*.rb']
|
41
|
+
end
|
42
|
+
|
43
|
+
Rake::TestTask.new('configure') do |t|
|
44
|
+
t.verbose = true
|
45
|
+
t.warning = true
|
46
|
+
t.test_files = FileList['test/test_win32_service_configure.rb']
|
47
|
+
end
|
48
|
+
|
49
|
+
Rake::TestTask.new('control') do |t|
|
50
|
+
t.verbose = true
|
51
|
+
t.warning = true
|
52
|
+
t.test_files = FileList['test/test_win32_service.rb']
|
53
|
+
end
|
54
|
+
|
55
|
+
Rake::TestTask.new('create') do |t|
|
56
|
+
t.verbose = true
|
57
|
+
t.warning = true
|
58
|
+
t.test_files = FileList['test/test_win32_service_create.rb']
|
59
|
+
end
|
60
|
+
|
61
|
+
Rake::TestTask.new('info') do |t|
|
62
|
+
t.verbose = true
|
63
|
+
t.warning = true
|
64
|
+
t.test_files = FileList['test/test_win32_service_info.rb']
|
65
|
+
end
|
66
|
+
|
67
|
+
Rake::TestTask.new('status') do |t|
|
68
|
+
t.verbose = true
|
69
|
+
t.warning = true
|
70
|
+
t.test_files = FileList['test/test_win32_service_status.rb']
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
task :all do
|
75
|
+
Rake.application[:clean].execute
|
76
|
+
end
|
77
|
+
|
78
|
+
task :daemon do
|
79
|
+
Rake.application[:clean].execute
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
task :default => 'test:all'
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.1
|
data/appveyor.yml
CHANGED
@@ -1,48 +1,48 @@
|
|
1
|
-
version: '{build}'
|
2
|
-
branches:
|
3
|
-
only:
|
4
|
-
- ffi
|
5
|
-
skip_tags: true
|
6
|
-
clone_depth: 10
|
7
|
-
environment:
|
8
|
-
matrix:
|
9
|
-
- ruby_version: 193
|
10
|
-
ruby_dir: 1.9.1
|
11
|
-
- ruby_version: 200
|
12
|
-
ruby_dir: 2.0.0
|
13
|
-
- ruby_version: 200-x64
|
14
|
-
ruby_dir: 2.0.0
|
15
|
-
- ruby_version: 21
|
16
|
-
ruby_dir: 2.1.0
|
17
|
-
- ruby_version: 21-x64
|
18
|
-
ruby_dir: 2.1.0
|
19
|
-
- ruby_version: 22
|
20
|
-
ruby_dir: 2.2.0
|
21
|
-
- ruby_version: 22-x64
|
22
|
-
ruby_dir: 2.2.0
|
23
|
-
install:
|
24
|
-
- ps: >-
|
25
|
-
$env:path = "C:\Ruby" + $env:ruby_version + "\bin;" + $env:path
|
26
|
-
|
27
|
-
$tpath = "C:\Ruby" + $env:ruby_version + "\lib\ruby\" + $env:ruby_dir + "\test"
|
28
|
-
|
29
|
-
if ((test-path $tpath) -eq $True){ rm -recurse -force $tpath }
|
30
|
-
|
31
|
-
gem update --system > $null
|
32
|
-
|
33
|
-
if ((gem query -i ffi) -eq $False){ gem install ffi --no-document }
|
34
|
-
|
35
|
-
if ((gem query -i win32-security) -eq $False){ gem install win32-security --no-document }
|
36
|
-
|
37
|
-
if ((gem query -i test-unit -v ">= 3.0") -eq $False){ gem install test-unit --no-document }
|
38
|
-
cache:
|
39
|
-
- C:\Ruby193\lib\ruby\gems\1.9.1
|
40
|
-
- C:\Ruby200\lib\ruby\gems\2.0.0
|
41
|
-
- C:\Ruby200-x64\lib\ruby\gems\2.0.0
|
42
|
-
- C:\Ruby21\lib\ruby\gems\2.1.0
|
43
|
-
- C:\Ruby21-x64\lib\ruby\gems\2.1.0
|
44
|
-
- C:\Ruby22\lib\ruby\gems\2.2.0
|
45
|
-
- C:\Ruby22-x64\lib\ruby\gems\2.2.0
|
46
|
-
build: off
|
47
|
-
test_script:
|
48
|
-
- cmd: rake
|
1
|
+
version: '{build}'
|
2
|
+
branches:
|
3
|
+
only:
|
4
|
+
- ffi
|
5
|
+
skip_tags: true
|
6
|
+
clone_depth: 10
|
7
|
+
environment:
|
8
|
+
matrix:
|
9
|
+
- ruby_version: 193
|
10
|
+
ruby_dir: 1.9.1
|
11
|
+
- ruby_version: 200
|
12
|
+
ruby_dir: 2.0.0
|
13
|
+
- ruby_version: 200-x64
|
14
|
+
ruby_dir: 2.0.0
|
15
|
+
- ruby_version: 21
|
16
|
+
ruby_dir: 2.1.0
|
17
|
+
- ruby_version: 21-x64
|
18
|
+
ruby_dir: 2.1.0
|
19
|
+
- ruby_version: 22
|
20
|
+
ruby_dir: 2.2.0
|
21
|
+
- ruby_version: 22-x64
|
22
|
+
ruby_dir: 2.2.0
|
23
|
+
install:
|
24
|
+
- ps: >-
|
25
|
+
$env:path = "C:\Ruby" + $env:ruby_version + "\bin;" + $env:path
|
26
|
+
|
27
|
+
$tpath = "C:\Ruby" + $env:ruby_version + "\lib\ruby\" + $env:ruby_dir + "\test"
|
28
|
+
|
29
|
+
if ((test-path $tpath) -eq $True){ rm -recurse -force $tpath }
|
30
|
+
|
31
|
+
gem update --system > $null
|
32
|
+
|
33
|
+
if ((gem query -i ffi) -eq $False){ gem install ffi --no-document }
|
34
|
+
|
35
|
+
if ((gem query -i win32-security) -eq $False){ gem install win32-security --no-document }
|
36
|
+
|
37
|
+
if ((gem query -i test-unit -v ">= 3.0") -eq $False){ gem install test-unit --no-document }
|
38
|
+
cache:
|
39
|
+
- C:\Ruby193\lib\ruby\gems\1.9.1
|
40
|
+
- C:\Ruby200\lib\ruby\gems\2.0.0
|
41
|
+
- C:\Ruby200-x64\lib\ruby\gems\2.0.0
|
42
|
+
- C:\Ruby21\lib\ruby\gems\2.1.0
|
43
|
+
- C:\Ruby21-x64\lib\ruby\gems\2.1.0
|
44
|
+
- C:\Ruby22\lib\ruby\gems\2.2.0
|
45
|
+
- C:\Ruby22-x64\lib\ruby\gems\2.2.0
|
46
|
+
build: off
|
47
|
+
test_script:
|
48
|
+
- cmd: rake
|
data/doc/daemon.txt
CHANGED
@@ -1,157 +1,157 @@
|
|
1
|
-
= Description
|
2
|
-
The Daemon class is a wrapper class that allows you to run your code as a
|
3
|
-
Windows service.
|
4
|
-
|
5
|
-
= Synopsis
|
6
|
-
class Daemon
|
7
|
-
def service_main
|
8
|
-
while running?
|
9
|
-
sleep 3
|
10
|
-
File.open("c:\\test.log", "a"){ |f| f.puts "service is running" }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
Daemon.mainloop
|
16
|
-
|
17
|
-
= Singleton Methods
|
18
|
-
Daemon.mainloop
|
19
|
-
This is the method that actually puts your code into a loop and allows it
|
20
|
-
to run as a service. The code that is actually run while in the mainloop
|
21
|
-
is what you defined in the Daemon#service_main method.
|
22
|
-
|
23
|
-
= Instance Methods
|
24
|
-
Daemon#running?
|
25
|
-
Returns whether or not the daemon is running. This is just a shortcut
|
26
|
-
for checking if the state is RUNNING, PAUSED or IDLE.
|
27
|
-
|
28
|
-
This is typically used within your service_main method. See the
|
29
|
-
demo_daemon.rb file in the 'examples' directory for an example of how it's
|
30
|
-
used in practice.
|
31
|
-
|
32
|
-
Daemon#service_init
|
33
|
-
Any code defined defined within this method occurs before service_main is
|
34
|
-
reached. Any initialization code that takes more than two seconds to
|
35
|
-
execute should be placed here. Otherwise, your service may timeout when
|
36
|
-
you try to start it.
|
37
|
-
|
38
|
-
Daemon#service_main(*args)
|
39
|
-
You are expected to define your own service_main() method. The code
|
40
|
-
defined in this method is the code that will run while running as a
|
41
|
-
service.
|
42
|
-
|
43
|
-
Any +args+ passed to Service.start are passed to this method.
|
44
|
-
|
45
|
-
Daemon#state
|
46
|
-
Returns the current state of the Daemon. For a list of valid states, see
|
47
|
-
the Constants section below.
|
48
|
-
|
49
|
-
= Signal Event Hooks
|
50
|
-
These methods are called if defined within your Daemon class, and the
|
51
|
-
appropriate signal is received by your service.
|
52
|
-
|
53
|
-
Daemon#service_stop
|
54
|
-
Called if the service receives a SERVICE_CONTROL_STOP signal. This is
|
55
|
-
what the Service.stop() method sends.
|
56
|
-
|
57
|
-
Daemon#service_pause
|
58
|
-
Called if the service receives a SERVICE_CONTROL_PAUSE signal. This is
|
59
|
-
what the Service.pause() method sends.
|
60
|
-
|
61
|
-
Daemon#service_resume
|
62
|
-
Called if the service receives a SERVICE_CONTROL_CONTINUE signal. This
|
63
|
-
is what the Service.resume() method sends.
|
64
|
-
|
65
|
-
Daemon#service_interrogate
|
66
|
-
Called if the service receives a SERVICE_CONTROL_INTERROGATE signal. This
|
67
|
-
notifies a service that it should report its current status information to
|
68
|
-
the service control manager.
|
69
|
-
|
70
|
-
Daemon#service_shutdown
|
71
|
-
Called if the service receives a SERVICE_CONTROL_SHUTDOWN signal.
|
72
|
-
|
73
|
-
Daemon#service_netbindadd
|
74
|
-
Called if the service receives a SERVICE_CONTROL_NETBINDADD signal. This
|
75
|
-
notifies a network service that there is a new component for binding.
|
76
|
-
|
77
|
-
Daemon#service_netbinddisable
|
78
|
-
Called if the service receives a SERVICE_CONTROL_NETBINDDISABLE signal.
|
79
|
-
This notifies a network service that one of its bindings has been
|
80
|
-
disabled.
|
81
|
-
|
82
|
-
Daemon#service_netbindenable
|
83
|
-
Called if the service receives a SERVICE_CONTROL_NETBINDENABLE signal.
|
84
|
-
This Notifies a network service that a disabled binding has been enabled.
|
85
|
-
|
86
|
-
Daemon#service_netbindremove
|
87
|
-
Called if the service receives a SERVICE_CONTROL_NETBINDREMOVE signal.
|
88
|
-
This notifies a network service that that a component for binding has
|
89
|
-
been removed.
|
90
|
-
|
91
|
-
Daemon#service_paramchange
|
92
|
-
Called if the service receives a SERVICE_CONTROL_PARAMCHANGE signal.
|
93
|
-
This notifies a service that its startup parameters have changed.
|
94
|
-
|
95
|
-
= Constants
|
96
|
-
|
97
|
-
=== Service state constants
|
98
|
-
Daemon::CONTINUE_PENDING
|
99
|
-
The service continue is pending.
|
100
|
-
|
101
|
-
Daemon::PAUSE_PENDING
|
102
|
-
The service pause is pending.
|
103
|
-
|
104
|
-
Daemon::PAUSED
|
105
|
-
The service is paused (but not STOPPED).
|
106
|
-
|
107
|
-
Daemon::RUNNING
|
108
|
-
The service is running.
|
109
|
-
|
110
|
-
Daemon::START_PENDING
|
111
|
-
The service is starting (but is not yet in a RUNNING state).
|
112
|
-
|
113
|
-
Daemon::STOP_PENDING
|
114
|
-
The service is stopping (but is not yet in a STOPPED state).
|
115
|
-
|
116
|
-
Daemon::STOPPED
|
117
|
-
The service is not running.
|
118
|
-
|
119
|
-
Daemon::IDLE
|
120
|
-
The service is running, in an idle state. This is a custom state that
|
121
|
-
we added that gets around a thread blocking issue.
|
122
|
-
|
123
|
-
= Notes
|
124
|
-
You must create a service before you can actually run it. Look in the
|
125
|
-
examples directory for the files 'demo_daemon.rb' and 'demodaemon_ctl.rb'.
|
126
|
-
They're small and straightforward examples of how to control, install and
|
127
|
-
setup your own Daemon.
|
128
|
-
|
129
|
-
= Known Bugs
|
130
|
-
None known. Please report any bugs you find on the issue tracker at
|
131
|
-
https//github.com/djberg96/win32-service
|
132
|
-
|
133
|
-
= Future Plans
|
134
|
-
None at this time.
|
135
|
-
|
136
|
-
Suggestions welcome. Please post them on the github project page at
|
137
|
-
https//github.com/djberg96/win32-service
|
138
|
-
|
139
|
-
= Acknowledgements
|
140
|
-
Many thanks go to Patrick Hurley for providing the fix for the thread
|
141
|
-
blocking issue for the original C code. Thanks also go to Kevin Burge for
|
142
|
-
his patch that solved service responsiveness issues.
|
143
|
-
|
144
|
-
= Copyright
|
145
|
-
(C) 2003-2016 Daniel J. Berger, All Rights Reserved
|
146
|
-
|
147
|
-
= License
|
148
|
-
Artistic 2.0
|
149
|
-
|
150
|
-
= Warranty
|
151
|
-
This package is provided "as is" and without any express or
|
152
|
-
implied warranties, including, without limitation, the implied
|
153
|
-
warranties of merchantability and fitness for a particular purpose.
|
154
|
-
|
155
|
-
= Author(s)
|
156
|
-
* Daniel J. Berger
|
157
|
-
* Park Heesob
|
1
|
+
= Description
|
2
|
+
The Daemon class is a wrapper class that allows you to run your code as a
|
3
|
+
Windows service.
|
4
|
+
|
5
|
+
= Synopsis
|
6
|
+
class Daemon
|
7
|
+
def service_main
|
8
|
+
while running?
|
9
|
+
sleep 3
|
10
|
+
File.open("c:\\test.log", "a"){ |f| f.puts "service is running" }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Daemon.mainloop
|
16
|
+
|
17
|
+
= Singleton Methods
|
18
|
+
Daemon.mainloop
|
19
|
+
This is the method that actually puts your code into a loop and allows it
|
20
|
+
to run as a service. The code that is actually run while in the mainloop
|
21
|
+
is what you defined in the Daemon#service_main method.
|
22
|
+
|
23
|
+
= Instance Methods
|
24
|
+
Daemon#running?
|
25
|
+
Returns whether or not the daemon is running. This is just a shortcut
|
26
|
+
for checking if the state is RUNNING, PAUSED or IDLE.
|
27
|
+
|
28
|
+
This is typically used within your service_main method. See the
|
29
|
+
demo_daemon.rb file in the 'examples' directory for an example of how it's
|
30
|
+
used in practice.
|
31
|
+
|
32
|
+
Daemon#service_init
|
33
|
+
Any code defined defined within this method occurs before service_main is
|
34
|
+
reached. Any initialization code that takes more than two seconds to
|
35
|
+
execute should be placed here. Otherwise, your service may timeout when
|
36
|
+
you try to start it.
|
37
|
+
|
38
|
+
Daemon#service_main(*args)
|
39
|
+
You are expected to define your own service_main() method. The code
|
40
|
+
defined in this method is the code that will run while running as a
|
41
|
+
service.
|
42
|
+
|
43
|
+
Any +args+ passed to Service.start are passed to this method.
|
44
|
+
|
45
|
+
Daemon#state
|
46
|
+
Returns the current state of the Daemon. For a list of valid states, see
|
47
|
+
the Constants section below.
|
48
|
+
|
49
|
+
= Signal Event Hooks
|
50
|
+
These methods are called if defined within your Daemon class, and the
|
51
|
+
appropriate signal is received by your service.
|
52
|
+
|
53
|
+
Daemon#service_stop
|
54
|
+
Called if the service receives a SERVICE_CONTROL_STOP signal. This is
|
55
|
+
what the Service.stop() method sends.
|
56
|
+
|
57
|
+
Daemon#service_pause
|
58
|
+
Called if the service receives a SERVICE_CONTROL_PAUSE signal. This is
|
59
|
+
what the Service.pause() method sends.
|
60
|
+
|
61
|
+
Daemon#service_resume
|
62
|
+
Called if the service receives a SERVICE_CONTROL_CONTINUE signal. This
|
63
|
+
is what the Service.resume() method sends.
|
64
|
+
|
65
|
+
Daemon#service_interrogate
|
66
|
+
Called if the service receives a SERVICE_CONTROL_INTERROGATE signal. This
|
67
|
+
notifies a service that it should report its current status information to
|
68
|
+
the service control manager.
|
69
|
+
|
70
|
+
Daemon#service_shutdown
|
71
|
+
Called if the service receives a SERVICE_CONTROL_SHUTDOWN signal.
|
72
|
+
|
73
|
+
Daemon#service_netbindadd
|
74
|
+
Called if the service receives a SERVICE_CONTROL_NETBINDADD signal. This
|
75
|
+
notifies a network service that there is a new component for binding.
|
76
|
+
|
77
|
+
Daemon#service_netbinddisable
|
78
|
+
Called if the service receives a SERVICE_CONTROL_NETBINDDISABLE signal.
|
79
|
+
This notifies a network service that one of its bindings has been
|
80
|
+
disabled.
|
81
|
+
|
82
|
+
Daemon#service_netbindenable
|
83
|
+
Called if the service receives a SERVICE_CONTROL_NETBINDENABLE signal.
|
84
|
+
This Notifies a network service that a disabled binding has been enabled.
|
85
|
+
|
86
|
+
Daemon#service_netbindremove
|
87
|
+
Called if the service receives a SERVICE_CONTROL_NETBINDREMOVE signal.
|
88
|
+
This notifies a network service that that a component for binding has
|
89
|
+
been removed.
|
90
|
+
|
91
|
+
Daemon#service_paramchange
|
92
|
+
Called if the service receives a SERVICE_CONTROL_PARAMCHANGE signal.
|
93
|
+
This notifies a service that its startup parameters have changed.
|
94
|
+
|
95
|
+
= Constants
|
96
|
+
|
97
|
+
=== Service state constants
|
98
|
+
Daemon::CONTINUE_PENDING
|
99
|
+
The service continue is pending.
|
100
|
+
|
101
|
+
Daemon::PAUSE_PENDING
|
102
|
+
The service pause is pending.
|
103
|
+
|
104
|
+
Daemon::PAUSED
|
105
|
+
The service is paused (but not STOPPED).
|
106
|
+
|
107
|
+
Daemon::RUNNING
|
108
|
+
The service is running.
|
109
|
+
|
110
|
+
Daemon::START_PENDING
|
111
|
+
The service is starting (but is not yet in a RUNNING state).
|
112
|
+
|
113
|
+
Daemon::STOP_PENDING
|
114
|
+
The service is stopping (but is not yet in a STOPPED state).
|
115
|
+
|
116
|
+
Daemon::STOPPED
|
117
|
+
The service is not running.
|
118
|
+
|
119
|
+
Daemon::IDLE
|
120
|
+
The service is running, in an idle state. This is a custom state that
|
121
|
+
we added that gets around a thread blocking issue.
|
122
|
+
|
123
|
+
= Notes
|
124
|
+
You must create a service before you can actually run it. Look in the
|
125
|
+
examples directory for the files 'demo_daemon.rb' and 'demodaemon_ctl.rb'.
|
126
|
+
They're small and straightforward examples of how to control, install and
|
127
|
+
setup your own Daemon.
|
128
|
+
|
129
|
+
= Known Bugs
|
130
|
+
None known. Please report any bugs you find on the issue tracker at
|
131
|
+
https//github.com/djberg96/win32-service
|
132
|
+
|
133
|
+
= Future Plans
|
134
|
+
None at this time.
|
135
|
+
|
136
|
+
Suggestions welcome. Please post them on the github project page at
|
137
|
+
https//github.com/djberg96/win32-service
|
138
|
+
|
139
|
+
= Acknowledgements
|
140
|
+
Many thanks go to Patrick Hurley for providing the fix for the thread
|
141
|
+
blocking issue for the original C code. Thanks also go to Kevin Burge for
|
142
|
+
his patch that solved service responsiveness issues.
|
143
|
+
|
144
|
+
= Copyright
|
145
|
+
(C) 2003-2016 Daniel J. Berger, All Rights Reserved
|
146
|
+
|
147
|
+
= License
|
148
|
+
Artistic 2.0
|
149
|
+
|
150
|
+
= Warranty
|
151
|
+
This package is provided "as is" and without any express or
|
152
|
+
implied warranties, including, without limitation, the implied
|
153
|
+
warranties of merchantability and fitness for a particular purpose.
|
154
|
+
|
155
|
+
= Author(s)
|
156
|
+
* Daniel J. Berger
|
157
|
+
* Park Heesob
|