mongrel_service 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.
- data/COPYING +20 -0
- data/LICENSE +20 -0
- data/README +13 -0
- data/Rakefile +42 -0
- data/bin/mongrel_service +153 -0
- data/lib/mongrel_service/init.rb +220 -0
- data/resources/defaults.yaml +2 -0
- data/tools/rakehelp.rb +106 -0
- metadata +70 -0
data/COPYING
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2006 Luis Lavena, luislavena@gmail.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2006 Luis Lavena, luislavena@gmail.com
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
== Mongrel Native Win32 Service Plugin
|
2
|
+
|
3
|
+
This plugin offer native win32 services for rails. This replace mongrel_rails_service.
|
4
|
+
It will work like before, with this this syntax when calling mongrel_rails:
|
5
|
+
|
6
|
+
service::install
|
7
|
+
service::remove
|
8
|
+
service::start
|
9
|
+
service::stop
|
10
|
+
service::status
|
11
|
+
|
12
|
+
= Author:
|
13
|
+
Luis Lavena
|
data/Rakefile
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/gempackagetask'
|
5
|
+
require 'rake/rdoctask'
|
6
|
+
require 'tools/rakehelp'
|
7
|
+
require 'fileutils'
|
8
|
+
include FileUtils
|
9
|
+
|
10
|
+
setup_tests
|
11
|
+
setup_clean ["pkg", "lib/*.bundle", "*.gem", ".config"]
|
12
|
+
|
13
|
+
setup_rdoc ['README', 'LICENSE', 'COPYING', 'lib/**/*.rb', 'doc/**/*.rdoc']
|
14
|
+
|
15
|
+
desc "Does a full compile, test run"
|
16
|
+
task :default => [:test, :package]
|
17
|
+
|
18
|
+
version="0.1"
|
19
|
+
name="mongrel_service"
|
20
|
+
|
21
|
+
setup_gem(name, version) do |spec|
|
22
|
+
spec.summary = "Mongrel Native Win32 Service Plugin for Rails"
|
23
|
+
spec.description = "This plugin offer native win32 services for rails, powered by Mongrel."
|
24
|
+
spec.author="Luis Lavena"
|
25
|
+
|
26
|
+
# added mongrel_service executable
|
27
|
+
spec.executables = ["mongrel_service"]
|
28
|
+
|
29
|
+
spec.add_dependency('gem_plugin', '>= 0.2.1')
|
30
|
+
spec.add_dependency('mongrel', '>= 0.3.12.4')
|
31
|
+
spec.files += Dir.glob("resources/**/*")
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
task :install => [:test, :package] do
|
36
|
+
sh %{gem install pkg/#{name}-#{version}.gem}
|
37
|
+
end
|
38
|
+
|
39
|
+
task :uninstall => [:clean] do
|
40
|
+
sh %{gem uninstall #{name}}
|
41
|
+
end
|
42
|
+
|
data/bin/mongrel_service
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'win32/service'
|
3
|
+
require 'mongrel'
|
4
|
+
require 'mongrel/rails'
|
5
|
+
require 'optparse'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
# Avoid curious users from running this script from command line
|
9
|
+
if ENV["HOMEDRIVE"]!=nil
|
10
|
+
puts "mongrel_service is not designed to run form commandline,"
|
11
|
+
puts "please use mongrel_rails service:: commands to create a win32 service."
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
15
|
+
# We need to use OpenProcess and SetProcessAffinityMask on WinNT/2K/XP for
|
16
|
+
# binding the process to each cpu.
|
17
|
+
# Kernel32 Module Just for Win32 :D
|
18
|
+
require 'dl/win32'
|
19
|
+
|
20
|
+
module Kernel32
|
21
|
+
[
|
22
|
+
%w/OpenProcess LLL L/,
|
23
|
+
%w/SetProcessAffinityMask LL L/,
|
24
|
+
].each do |fn|
|
25
|
+
const_set fn[0].intern, Win32API.new('kernel32.dll', *fn)
|
26
|
+
end
|
27
|
+
|
28
|
+
PROCESS_ALL_ACCESS = 0x1f0fff
|
29
|
+
|
30
|
+
module_function
|
31
|
+
|
32
|
+
def set_affinity(pid, cpu)
|
33
|
+
handle = OpenProcess.call(PROCESS_ALL_ACCESS, 0, pid)
|
34
|
+
|
35
|
+
# CPU mask is a bit weird, hehehe :)
|
36
|
+
# default mask for CPU 1
|
37
|
+
mask = 1
|
38
|
+
mask = %w{1 2 4 8 16 32 64 128}[cpu.to_i - 1] if cpu.to_i.between?(1, 8)
|
39
|
+
|
40
|
+
SetProcessAffinityMask.call(handle, mask.to_i)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
# End Kernel32 Module
|
44
|
+
|
45
|
+
# RailsService code here
|
46
|
+
class RailsService < Win32::Daemon
|
47
|
+
def initialize(settings)
|
48
|
+
@settings = settings
|
49
|
+
end
|
50
|
+
|
51
|
+
def service_init
|
52
|
+
@config = Mongrel::Rails::RailsConfigurator.new(@settings) do
|
53
|
+
log "Starting Mongrel in #{defaults[:environment]} mode at #{defaults[:host]}:#{defaults[:port]}"
|
54
|
+
|
55
|
+
listener do
|
56
|
+
mime = {}
|
57
|
+
if defaults[:mime_map]
|
58
|
+
log "Loading additional MIME types from #{defaults[:mime_map]}"
|
59
|
+
mime = load_mime_map(defaults[:mime_map], mime)
|
60
|
+
end
|
61
|
+
|
62
|
+
if defaults[:debug]
|
63
|
+
log "Installing debugging prefixed filters. Look in log/mongrel_debug for the files."
|
64
|
+
debug "/"
|
65
|
+
end
|
66
|
+
|
67
|
+
log "Starting Rails in environment #{defaults[:environment]} ..."
|
68
|
+
uri "/", :handler => rails(:mime => mime)
|
69
|
+
log "Rails loaded."
|
70
|
+
|
71
|
+
#log "Loading any Rails specific GemPlugins"
|
72
|
+
#load_plugins
|
73
|
+
|
74
|
+
if defaults[:config_script]
|
75
|
+
log "Loading #{defaults[:config_script]} external config script"
|
76
|
+
run_config(defaults[:config_script])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
def service_main
|
84
|
+
@config.run
|
85
|
+
@config.log "Mongrel available at #{@settings[:host]}:#{@settings[:port]}"
|
86
|
+
|
87
|
+
while state == RUNNING
|
88
|
+
sleep 1
|
89
|
+
end
|
90
|
+
|
91
|
+
@config.stop
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
# default options
|
97
|
+
OPTIONS = {
|
98
|
+
:environment => ENV['RAILS_ENV'] || "development",
|
99
|
+
:port => 3000,
|
100
|
+
:address => "0.0.0.0",
|
101
|
+
:log_file => "log/mongrel.log",
|
102
|
+
:pid_file => "log/mongrel.pid",
|
103
|
+
:num_procs => 1024,
|
104
|
+
:timeout => 0,
|
105
|
+
:mime_map => nil,
|
106
|
+
:cwd => Dir.pwd,
|
107
|
+
:docroot => "public",
|
108
|
+
:debug => false,
|
109
|
+
:config_file => nil,
|
110
|
+
:config_script => nil,
|
111
|
+
:cpu => nil
|
112
|
+
}
|
113
|
+
|
114
|
+
ARGV.options do |opts|
|
115
|
+
opts.on('-e', '--environment ENV', "Rails environment to run as") { |OPTIONS[:environment]| }
|
116
|
+
opts.on('-p', '--port PORT', "Which port to bind to") { |OPTIONS[:port]| }
|
117
|
+
opts.on('-a', '--address ADDR', "Address to bind to") { |OPTIONS[:address]| }
|
118
|
+
opts.on('-l', '--log FILE', "Where to write log messages") { |OPTIONS[:log_file]| }
|
119
|
+
opts.on('-P', '--pid FILE', "Where to write the PID") { |OPTIONS[:pid_file]| }
|
120
|
+
opts.on('-n', '--num-procs INT', "Number of processors active before clients denied") { |OPTIONS[:num_procs]| }
|
121
|
+
opts.on('-t', '--timeout TIME', "Timeout all requests after 100th seconds time") { |OPTIONS[:timeout]| }
|
122
|
+
opts.on('-m', '--mime PATH', "A YAML file that lists additional MIME types") { |OPTIONS[:mime_map]| }
|
123
|
+
opts.on('-c', '--chdir PATH', "Change to dir before starting (will be expanded)") { |OPTIONS[:cwd]| }
|
124
|
+
opts.on('-r', '--root PATH', "Set the document root (default 'public')") { |OPTIONS[:docroot]| }
|
125
|
+
opts.on('-B', '--debug', "Enable debugging mode") { |OPTIONS[:debug]| }
|
126
|
+
opts.on('-C', '--config FILE', "Use a config file") { |OPTIONS[:config_file]| }
|
127
|
+
opts.on('-S', '--script FILE', "Load the given file as an extra config script.") { |OPTIONS[:config_script]| }
|
128
|
+
opts.on('-u', '--cpu CPU', "Bind the process to specific cpu, starting from 1.") { |OPTIONS[:cpu]| }
|
129
|
+
|
130
|
+
opts.parse!
|
131
|
+
end
|
132
|
+
|
133
|
+
# We must bind to a specific cpu?
|
134
|
+
if OPTIONS[:cpu]
|
135
|
+
Kernel32.set_affinity(Process.pid, OPTIONS[:cpu])
|
136
|
+
end
|
137
|
+
|
138
|
+
# expand path
|
139
|
+
OPTIONS[:cwd] = File.expand_path(OPTIONS[:cwd])
|
140
|
+
|
141
|
+
# chdir to that path
|
142
|
+
Dir.chdir(OPTIONS[:cwd])
|
143
|
+
|
144
|
+
# redirecting STDERR to a file so we could trace it.
|
145
|
+
STDERR.reopen("log/service.log", "w")
|
146
|
+
STDERR.sync = true
|
147
|
+
|
148
|
+
#FIXME: I commented this because fails during load_plugins from configurator, we need to fix
|
149
|
+
#GemPlugin::Manager.instance.load "mongrel" => GemPlugin::INCLUDE, "rails" => GemPlugin::EXCLUDE
|
150
|
+
|
151
|
+
# initialize the daemon and pass control to win32/service
|
152
|
+
svc = RailsService.new(OPTIONS)
|
153
|
+
svc.mainloop
|
@@ -0,0 +1,220 @@
|
|
1
|
+
require 'gem_plugin'
|
2
|
+
require 'mongrel'
|
3
|
+
require 'mongrel/rails'
|
4
|
+
require 'rbconfig'
|
5
|
+
require 'win32/service'
|
6
|
+
|
7
|
+
|
8
|
+
module Service
|
9
|
+
class Install < GemPlugin::Plugin "/commands"
|
10
|
+
include Mongrel::Command::Base
|
11
|
+
|
12
|
+
def configure
|
13
|
+
options [
|
14
|
+
['-N', '--name SVC_NAME', "Required name for the service to be registered/installed.", :@svc_name, nil],
|
15
|
+
['-D', '--display SVC_DISPLAY', "Adjust the display name of the service.", :@svc_display, nil],
|
16
|
+
["-e", "--environment ENV", "Rails environment to run as", :@environment, ENV['RAILS_ENV'] || "development"],
|
17
|
+
['-p', '--port PORT', "Which port to bind to", :@port, 3000],
|
18
|
+
['-a', '--address ADDR', "Address to bind to", :@address, "0.0.0.0"],
|
19
|
+
['-l', '--log FILE', "Where to write log messages", :@log_file, "log/mongrel.log"],
|
20
|
+
['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"],
|
21
|
+
['-n', '--num-procs INT', "Number of processors active before clients denied", :@num_procs, 1024],
|
22
|
+
['-t', '--timeout TIME', "Timeout all requests after 100th seconds time", :@timeout, 0],
|
23
|
+
['-m', '--mime PATH', "A YAML file that lists additional MIME types", :@mime_map, nil],
|
24
|
+
['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],
|
25
|
+
['-r', '--root PATH', "Set the document root (default 'public')", :@docroot, "public"],
|
26
|
+
['-B', '--debug', "Enable debugging mode", :@debug, false],
|
27
|
+
['-C', '--config PATH', "Use a config file", :@config_file, nil],
|
28
|
+
['-S', '--script PATH', "Load the given file as an extra config script.", :@config_script, nil],
|
29
|
+
['-u', '--cpu CPU', "Bind the process to specific cpu, starting from 1.", :@cpu, nil]
|
30
|
+
]
|
31
|
+
end
|
32
|
+
|
33
|
+
# When we validate the options, we need to make sure the --root is actually RAILS_ROOT
|
34
|
+
# of the rails application we wanted to serve, because later "as service" no error
|
35
|
+
# show to trace this.
|
36
|
+
def validate
|
37
|
+
@cwd = File.expand_path(@cwd)
|
38
|
+
valid_dir? @cwd, "Invalid path to change to: #@cwd"
|
39
|
+
|
40
|
+
# change there to start, then we'll have to come back after daemonize
|
41
|
+
Dir.chdir(@cwd)
|
42
|
+
|
43
|
+
# start with the premise of app really exist.
|
44
|
+
app_exist = true
|
45
|
+
%w{app config db log public}.each do |path|
|
46
|
+
if !File.directory?(File.join(@cwd, path))
|
47
|
+
app_exist = false
|
48
|
+
break
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
valid? app_exist == true, "The path you specified isn't a valid Rails application."
|
53
|
+
|
54
|
+
valid_dir? File.dirname(@log_file), "Path to log file not valid: #@log_file"
|
55
|
+
valid_dir? File.dirname(@pid_file), "Path to pid file not valid: #@pid_file"
|
56
|
+
valid_dir? @docroot, "Path to docroot not valid: #@docroot"
|
57
|
+
valid_exists? @mime_map, "MIME mapping file does not exist: #@mime_map" if @mime_map
|
58
|
+
valid_exists? @config_file, "Config file not there: #@config_file" if @config_file
|
59
|
+
|
60
|
+
# Validate the number of cpu to bind to.
|
61
|
+
valid? @cpu.to_i > 0, "You must specify a numeric value for cpu. (1..8)" if @cpu
|
62
|
+
|
63
|
+
# We should validate service existance here, right Zed?
|
64
|
+
begin
|
65
|
+
valid? !Win32::Service.exists?(@svc_name), "The service already exist, please remove it first."
|
66
|
+
rescue
|
67
|
+
end
|
68
|
+
|
69
|
+
valid? @svc_name != nil, "A service name is mandatory."
|
70
|
+
|
71
|
+
# default service display to service name
|
72
|
+
@svc_display = @svc_name if !@svc_display
|
73
|
+
|
74
|
+
return @valid
|
75
|
+
end
|
76
|
+
|
77
|
+
def run
|
78
|
+
# command line setting override config file settings
|
79
|
+
@options = { :host => @address, :port => @port, :cwd => @cwd,
|
80
|
+
:log_file => @log_file, :pid_file => @pid_file, :environment => @environment,
|
81
|
+
:docroot => @docroot, :mime_map => @mime_map,
|
82
|
+
:debug => @debug, :includes => ["mongrel"], :config_script => @config_script,
|
83
|
+
:num_procs => @num_procs, :timeout => @timeout, :cpu => @cpu
|
84
|
+
}
|
85
|
+
|
86
|
+
if @config_file
|
87
|
+
STDERR.puts "** Loading settings from #{@config_file} (command line options override)."
|
88
|
+
conf = YAML.load_file(@config_file)
|
89
|
+
@options = conf.merge(@options)
|
90
|
+
end
|
91
|
+
|
92
|
+
argv = []
|
93
|
+
|
94
|
+
# ruby.exe instead of rubyw.exe due a exception raised when stoping the service!
|
95
|
+
argv << '"' + Config::CONFIG['bindir'] + '/ruby.exe' + '"'
|
96
|
+
|
97
|
+
# add service_script, we now use the rubygem powered one
|
98
|
+
argv << '"' + Config::CONFIG['bindir'] + '/mongrel_service' + '"'
|
99
|
+
|
100
|
+
# now the options
|
101
|
+
argv << "-e #{@options[:environment]}" if @options[:environment]
|
102
|
+
argv << "-p #{@options[:port]}"
|
103
|
+
argv << "-a #{@options[:address]}" if @options[:address]
|
104
|
+
argv << "-l \"#{@options[:log_file]}\"" if @options[:log_file]
|
105
|
+
argv << "-P \"#{@options[:pid_file]}\""
|
106
|
+
argv << "-c \"#{@options[:cwd]}\"" if @options[:cwd]
|
107
|
+
argv << "-t #{@options[:timeout]}" if @options[:timeout]
|
108
|
+
argv << "-m \"#{@options[:mime_map]}\"" if @options[:mime_map]
|
109
|
+
argv << "-r \"#{@options[:docroot]}\"" if @options[:docroot]
|
110
|
+
argv << "-n #{@options[:num_procs]}" if @options[:num_procs]
|
111
|
+
argv << "-B" if @options[:debug]
|
112
|
+
argv << "-S \"#{@options[:config_script]}\"" if @options[:config_script]
|
113
|
+
argv << "-u #{@options[:cpu.to_i]}" if @options[:cpu]
|
114
|
+
|
115
|
+
svc = Win32::Service.new
|
116
|
+
begin
|
117
|
+
svc.create_service{ |s|
|
118
|
+
s.service_name = @svc_name
|
119
|
+
s.display_name = @svc_display
|
120
|
+
s.binary_path_name = argv.join ' '
|
121
|
+
s.dependencies = []
|
122
|
+
}
|
123
|
+
puts "Mongrel service '#{@svc_display}' installed as '#{@svc_name}'."
|
124
|
+
rescue Win32::ServiceError => err
|
125
|
+
puts "There was a problem installing the service:"
|
126
|
+
puts err
|
127
|
+
end
|
128
|
+
svc.close
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
module ServiceValidation
|
133
|
+
def configure
|
134
|
+
options [
|
135
|
+
['-N', '--name SVC_NAME', "Required name for the service to be registered/installed.", :@svc_name, nil],
|
136
|
+
]
|
137
|
+
end
|
138
|
+
|
139
|
+
def validate
|
140
|
+
valid? @svc_name != nil, "A service name is mandatory."
|
141
|
+
|
142
|
+
# Validate that the service exists
|
143
|
+
begin
|
144
|
+
valid? Win32::Service.exists?(@svc_name), "There is no service with that name, cannot proceed."
|
145
|
+
rescue
|
146
|
+
end
|
147
|
+
|
148
|
+
return @valid
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
class Remove < GemPlugin::Plugin "/commands"
|
153
|
+
include Mongrel::Command::Base
|
154
|
+
include ServiceValidation
|
155
|
+
|
156
|
+
def run
|
157
|
+
display_name = Win32::Service.getdisplayname(@svc_name)
|
158
|
+
|
159
|
+
begin
|
160
|
+
Win32::Service.stop(@svc_name)
|
161
|
+
rescue
|
162
|
+
end
|
163
|
+
begin
|
164
|
+
Win32::Service.delete(@svc_name)
|
165
|
+
rescue
|
166
|
+
end
|
167
|
+
puts "#{display_name} service removed."
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
class Start < GemPlugin::Plugin "/commands"
|
172
|
+
include Mongrel::Command::Base
|
173
|
+
include ServiceValidation
|
174
|
+
|
175
|
+
def run
|
176
|
+
display_name = Win32::Service.getdisplayname(@svc_name)
|
177
|
+
|
178
|
+
begin
|
179
|
+
Win32::Service.start(@svc_name)
|
180
|
+
started = false
|
181
|
+
while started == false
|
182
|
+
s = Win32::Service.status(@svc_name)
|
183
|
+
started = true if s.current_state == "running"
|
184
|
+
break if started == true
|
185
|
+
puts "One moment, " + s.current_state
|
186
|
+
sleep 1
|
187
|
+
end
|
188
|
+
puts "#{display_name} service started"
|
189
|
+
rescue Win32::ServiceError => err
|
190
|
+
puts "There was a problem starting the service:"
|
191
|
+
puts err
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
class Stop < GemPlugin::Plugin "/commands"
|
197
|
+
include Mongrel::Command::Base
|
198
|
+
include ServiceValidation
|
199
|
+
|
200
|
+
def run
|
201
|
+
display_name = Win32::Service.getdisplayname(@svc_name)
|
202
|
+
|
203
|
+
begin
|
204
|
+
Win32::Service.stop(@svc_name)
|
205
|
+
stopped = false
|
206
|
+
while stopped == false
|
207
|
+
s = Win32::Service.status(@svc_name)
|
208
|
+
stopped = true if s.current_state == "stopped"
|
209
|
+
break if stopped == true
|
210
|
+
puts "One moment, " + s.current_state
|
211
|
+
sleep 1
|
212
|
+
end
|
213
|
+
puts "#{display_name} service stopped"
|
214
|
+
rescue Win32::ServiceError => err
|
215
|
+
puts "There was a problem stopping the service:"
|
216
|
+
puts err
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
data/tools/rakehelp.rb
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
|
2
|
+
def make(makedir)
|
3
|
+
Dir.chdir(makedir) do
|
4
|
+
sh(PLATFORM =~ /win32/ ? 'nmake' : 'make')
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
|
9
|
+
def extconf(dir)
|
10
|
+
Dir.chdir(dir) do ruby "extconf.rb" end
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def setup_tests
|
15
|
+
Rake::TestTask.new do |t|
|
16
|
+
t.libs << "test"
|
17
|
+
t.test_files = FileList['test/test*.rb']
|
18
|
+
t.verbose = true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def setup_clean otherfiles
|
24
|
+
files = ['build/*', '**/*.o', '**/*.so', '**/*.a', 'lib/*-*', '**/*.log'] + otherfiles
|
25
|
+
CLEAN.include(files)
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def setup_rdoc files
|
30
|
+
Rake::RDocTask.new do |rdoc|
|
31
|
+
rdoc.rdoc_dir = 'doc/rdoc'
|
32
|
+
rdoc.options << '--line-numbers'
|
33
|
+
rdoc.rdoc_files.add(files)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def setup_extension(dir, extension)
|
39
|
+
ext = "ext/#{dir}"
|
40
|
+
ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
|
41
|
+
ext_files = FileList[
|
42
|
+
"#{ext}/*.c",
|
43
|
+
"#{ext}/*.h",
|
44
|
+
"#{ext}/extconf.rb",
|
45
|
+
"#{ext}/Makefile",
|
46
|
+
"lib"
|
47
|
+
]
|
48
|
+
|
49
|
+
task "lib" do
|
50
|
+
directory "lib"
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "Builds just the #{extension} extension"
|
54
|
+
task extension.to_sym => ["#{ext}/Makefile", ext_so ]
|
55
|
+
|
56
|
+
file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
|
57
|
+
extconf "#{ext}"
|
58
|
+
end
|
59
|
+
|
60
|
+
file ext_so => ext_files do
|
61
|
+
make "#{ext}"
|
62
|
+
cp ext_so, "lib"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def base_gem_spec(pkg_name, pkg_version)
|
68
|
+
pkg_version = pkg_version
|
69
|
+
pkg_name = pkg_name
|
70
|
+
pkg_file_name = "#{pkg_name}-#{pkg_version}"
|
71
|
+
Gem::Specification.new do |s|
|
72
|
+
s.name = pkg_name
|
73
|
+
s.version = pkg_version
|
74
|
+
s.platform = Gem::Platform::RUBY
|
75
|
+
s.has_rdoc = true
|
76
|
+
s.extra_rdoc_files = [ "README" ]
|
77
|
+
|
78
|
+
s.files = %w(COPYING LICENSE README Rakefile) +
|
79
|
+
Dir.glob("{bin,doc/rdoc,test,lib}/**/*") +
|
80
|
+
Dir.glob("ext/**/*.{h,c,rb}") +
|
81
|
+
Dir.glob("examples/**/*.rb") +
|
82
|
+
Dir.glob("tools/*.rb")
|
83
|
+
|
84
|
+
s.require_path = "lib"
|
85
|
+
s.extensions = FileList["ext/**/extconf.rb"].to_a
|
86
|
+
s.bindir = "bin"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def setup_gem(pkg_name, pkg_version)
|
91
|
+
spec = base_gem_spec(pkg_name, pkg_version)
|
92
|
+
yield spec if block_given?
|
93
|
+
|
94
|
+
Rake::GemPackageTask.new(spec) do |p|
|
95
|
+
p.gem_spec = spec
|
96
|
+
# win32 chokes on this
|
97
|
+
p.need_tar = true if RUBY_PLATFORM !~ /mswin/
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def setup_win32_gem(pkg_name, pkg_version)
|
102
|
+
spec = base_gem_spec(pkg_name, pkg_version)
|
103
|
+
yield spec if block_given?
|
104
|
+
|
105
|
+
Gem::Builder.new(spec).build
|
106
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.8.11
|
3
|
+
specification_version: 1
|
4
|
+
name: mongrel_service
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "0.1"
|
7
|
+
date: 2006-06-16 00:00:00 -04:00
|
8
|
+
summary: Mongrel Native Win32 Service Plugin for Rails
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email:
|
12
|
+
homepage:
|
13
|
+
rubyforge_project:
|
14
|
+
description: This plugin offer native win32 services for rails, powered by Mongrel.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
authors:
|
29
|
+
- Luis Lavena
|
30
|
+
files:
|
31
|
+
- COPYING
|
32
|
+
- LICENSE
|
33
|
+
- README
|
34
|
+
- Rakefile
|
35
|
+
- bin/mongrel_service
|
36
|
+
- lib/mongrel_service
|
37
|
+
- lib/mongrel_service/init.rb
|
38
|
+
- tools/rakehelp.rb
|
39
|
+
- resources/defaults.yaml
|
40
|
+
test_files: []
|
41
|
+
|
42
|
+
rdoc_options: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- README
|
46
|
+
executables:
|
47
|
+
- mongrel_service
|
48
|
+
extensions: []
|
49
|
+
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
dependencies:
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: gem_plugin
|
55
|
+
version_requirement:
|
56
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.2.1
|
61
|
+
version:
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: mongrel
|
64
|
+
version_requirement:
|
65
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 0.3.12.4
|
70
|
+
version:
|