mongrel_service 0.1 → 0.4.beta1

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 DELETED
@@ -1,20 +0,0 @@
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 DELETED
@@ -1,20 +0,0 @@
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 DELETED
@@ -1,13 +0,0 @@
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/bin/mongrel_service DELETED
@@ -1,153 +0,0 @@
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
data/tools/rakehelp.rb DELETED
@@ -1,106 +0,0 @@
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