win-service-manager 1.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.
- checksums.yaml +7 -0
- data/History.txt +6 -0
- data/Manifest.txt +6 -0
- data/README.rdoc +67 -0
- data/lib/win-service-manager.rb +73 -0
- metadata +64 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 0b41407d63fb3c6abaea5031856d95bbf3b9bf77
|
|
4
|
+
data.tar.gz: 870d3c815fe9ab9abde7b42ba97dd1fdb58d464c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ca882074025fc7da85937cb848d288f5d6460713737843e4153ada63e4ac9e181f721b5ba669e83469c6f591358b94e2933336106a6e4d1d0fe0ea2079a3840b
|
|
7
|
+
data.tar.gz: 8ccaa70a2b02b180cd7412028857a46383b4e910a308679798d5a52bc41eb3515509d090be5c6a6d3e1f322feda4fc657ab3e8ecaabd86050eddb20d6d688a60
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
= win-service-manager
|
|
2
|
+
by Ryan Castro (Originally by James Tucker)
|
|
3
|
+
http://github.com/ryancastro/win-service-manager/
|
|
4
|
+
|
|
5
|
+
== DESCRIPTION:
|
|
6
|
+
|
|
7
|
+
Install, configure, and manage Microsoft Windows services from Ruby. Using Microsoft's SRVany.exe from the MS Resource Toolkit, run a Ruby script as a Windows service.
|
|
8
|
+
|
|
9
|
+
== FEATURES/PROBLEMS:
|
|
10
|
+
|
|
11
|
+
* Turn any application into a Windows service using Srvany.exe. Manage existing services.
|
|
12
|
+
* Depending on how your Ruby process launches (Like rails, which uses a batch file), stopping the service may stop SRVany.exe, but leave the child batch running.
|
|
13
|
+
|
|
14
|
+
== SYNOPSIS:
|
|
15
|
+
|
|
16
|
+
#Create a new manager
|
|
17
|
+
sm = WinServiceManager.new(File.expand_path("srvany.exe"))
|
|
18
|
+
#Creat a new service. Name, exe, arguments, directory to run from, Service description
|
|
19
|
+
sm.create('foo service', 'c:\ruby18\bin\rubyw', 'my_awesome_daemon.rb', 'c:\daemon', "This is my Daemon Service" )
|
|
20
|
+
sm.start('foo service')
|
|
21
|
+
sm.stop('foo service')
|
|
22
|
+
sm.delete('foo service')
|
|
23
|
+
puts sm.list
|
|
24
|
+
|
|
25
|
+
== TURNING RAILS 4 INTO A WINDOWS SERVICE:
|
|
26
|
+
require 'win-service-manager'
|
|
27
|
+
service = WinServiceManager.new('c:\mc_ruby\srvany.exe')
|
|
28
|
+
service.create('Awesome Rails 4 service', 'c:\ruby200\bin\ruby', 'c:\ruby200\bin\rails server -e production', 'c:\projects\awesomerails', 'Rails 4 Service Description')
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
== REQUIREMENTS:
|
|
32
|
+
|
|
33
|
+
At the time of writing, some of the dependencies are only available as gems to
|
|
34
|
+
the 'x86-mswin32-60' platform. If you are installing on mingw, you can get
|
|
35
|
+
away with installing them using a specific --platform argument to rubygems.
|
|
36
|
+
|
|
37
|
+
* gem inst win32-service win32-registry
|
|
38
|
+
|
|
39
|
+
== INSTALL:
|
|
40
|
+
|
|
41
|
+
* gem inst win-service-manager
|
|
42
|
+
* To create services, download srvany.exe from Microsoft Resource Kit Tools and provide it's path to WinServiceManager
|
|
43
|
+
|
|
44
|
+
== LICENSE:
|
|
45
|
+
|
|
46
|
+
(The MIT License)
|
|
47
|
+
|
|
48
|
+
Copyright (c) 2008 James Tucker
|
|
49
|
+
|
|
50
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
51
|
+
a copy of this software and associated documentation files (the
|
|
52
|
+
'Software'), to deal in the Software without restriction, including
|
|
53
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
54
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
55
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
56
|
+
the following conditions:
|
|
57
|
+
|
|
58
|
+
The above copyright notice and this permission notice shall be
|
|
59
|
+
included in all copies or substantial portions of the Software.
|
|
60
|
+
|
|
61
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
62
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
63
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
64
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
65
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
66
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
67
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
require 'win32/service'
|
|
2
|
+
require 'win32/registry'
|
|
3
|
+
|
|
4
|
+
class WinServiceManager
|
|
5
|
+
#Name your service, provice a path to SRVANY.exe - found in the MS Windows Resource Kit
|
|
6
|
+
def initialize(srv_any_path = "#{ENV['ProgramFiles']}\\Windows Resource Kits\\Tools\\srvany.exe")
|
|
7
|
+
@name_key = ''
|
|
8
|
+
@srv_any_path = srv_any_path
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Create a new service. The service name will be appended to the name_key
|
|
12
|
+
# and inserted into the registry using Win32::Service. The arguments are
|
|
13
|
+
# then adjusted with win32-registry.
|
|
14
|
+
# One recommended pattern is to store persisence details about the service
|
|
15
|
+
# as yaml in the optional description field.
|
|
16
|
+
def create(name, command, args = '', app_directory = '', description = nil, options = {})
|
|
17
|
+
defaults = {
|
|
18
|
+
:service_type => Win32::Service::WIN32_OWN_PROCESS,
|
|
19
|
+
:start_type => Win32::Service::DEMAND_START,
|
|
20
|
+
:error_control => Win32::Service::ERROR_NORMAL
|
|
21
|
+
}.merge(options)
|
|
22
|
+
name = @name_key + name.to_s
|
|
23
|
+
options = defaults.merge(
|
|
24
|
+
:display_name => name,
|
|
25
|
+
:service_name => name,
|
|
26
|
+
:description => description || name,
|
|
27
|
+
:binary_path_name => @srv_any_path
|
|
28
|
+
)
|
|
29
|
+
Win32::Service.create(options)
|
|
30
|
+
registry(name) do |reg|
|
|
31
|
+
reg.create('Parameters') do |params|
|
|
32
|
+
params.write_i("Start", 3)
|
|
33
|
+
params.write_s("Application", command)
|
|
34
|
+
params.write_s("AppParameters", args)
|
|
35
|
+
params.write_s("AppDirectory", app_directory)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Mark a service for deletion (note, does not terminate the service)
|
|
41
|
+
def delete(name)
|
|
42
|
+
Win32::Service.delete(@name_key + name.to_s)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def start(name)
|
|
46
|
+
Win32::Service.start(@name_key + name.to_s)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def stop(name)
|
|
50
|
+
Win32::Service.stop(@name_key + name.to_s)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Returns an array of tuples of name and description
|
|
54
|
+
def list
|
|
55
|
+
services = Win32::Service.services.select do |svc|
|
|
56
|
+
# TODO in future, 1.8.7, can use start_with?
|
|
57
|
+
svc.display_name[0,@name_key.size] == @name_key
|
|
58
|
+
end
|
|
59
|
+
services.map do |svc_info|
|
|
60
|
+
name = svc_info.display_name
|
|
61
|
+
[name.slice(@name_key.size, name.size), svc_info.description]
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
private
|
|
66
|
+
def registry(name, &block)
|
|
67
|
+
Win32::Registry::HKEY_LOCAL_MACHINE.open(
|
|
68
|
+
"SYSTEM\\CurrentControlSet\\Services",
|
|
69
|
+
Win32::Registry::KEY_WRITE | Win32::Registry::KEY_READ
|
|
70
|
+
).open(name, &block)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: win-service-manager
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: '1.0'
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ryan Castro
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: win32-service
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.7.0
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.7.0
|
|
27
|
+
description: Create, configure, and manage Windows services from Ruby
|
|
28
|
+
email: git@ryancastro.com
|
|
29
|
+
executables: []
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files:
|
|
32
|
+
- History.txt
|
|
33
|
+
- README.rdoc
|
|
34
|
+
files:
|
|
35
|
+
- History.txt
|
|
36
|
+
- Manifest.txt
|
|
37
|
+
- README.rdoc
|
|
38
|
+
- lib/win-service-manager.rb
|
|
39
|
+
homepage: http://github.com/ryancastro/win-service-manager
|
|
40
|
+
licenses: []
|
|
41
|
+
metadata: {}
|
|
42
|
+
post_install_message:
|
|
43
|
+
rdoc_options:
|
|
44
|
+
- --main
|
|
45
|
+
- README.rdoc
|
|
46
|
+
require_paths:
|
|
47
|
+
- lib
|
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - '>='
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '0'
|
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - '>='
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '0'
|
|
58
|
+
requirements: []
|
|
59
|
+
rubyforge_project:
|
|
60
|
+
rubygems_version: 2.0.3
|
|
61
|
+
signing_key:
|
|
62
|
+
specification_version: 4
|
|
63
|
+
summary: Create, configure, and manage Windows services from Ruby
|
|
64
|
+
test_files: []
|