Changeset 404
- Timestamp:
- 11/20/06 22:06:45 (2 years ago)
- Files:
-
- branches/win32-native_service/projects/mongrel_service/Rakefile (modified) (2 diffs)
- branches/win32-native_service/projects/mongrel_service/bin/mongrel_service (deleted)
- branches/win32-native_service/projects/mongrel_service/lib/mongrel_service/init.rb (modified) (9 diffs)
- branches/win32-native_service/projects/mongrel_service/native/mongrel_service.bas (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/win32-native_service/projects/mongrel_service/Rakefile
r402 r404 17 17 task :default => [:test, :compile, :package] 18 18 19 version="0.3.0" 20 name="mongrel_service" 21 22 setup_gem(name, version) do |spec| 23 spec.summary = "Mongrel Native Win32 Service Plugin for Rails" 24 spec.description = "This plugin offer native win32 services for rails, powered by Mongrel." 25 spec.author="Luis Lavena" 26 27 # added mongrel_service executable 28 spec.executables = ["mongrel_service"] 29 30 spec.add_dependency('gem_plugin', '>= 0.2.1') 31 spec.add_dependency('mongrel', '>= 0.3.12.4') 32 spec.add_dependency('win32-service', '>= 0.5.0') 33 34 spec.files += Dir.glob("resources/**/*") 35 end 36 37 38 task :install => [:test, :package] do 39 sh %{gem install pkg/#{name}-#{version}.gem} 40 end 41 42 task :uninstall => [:clean] do 43 sh %{gem uninstall #{name}} 44 end 45 19 GEM_VERSION = "0.3.0" 20 GEM_NAME = "mongrel_service" 46 21 47 22 # ServiceFB namespace (lib) … … 93 68 task :compile => "native:build" 94 69 task :clobber => "native:clobber" 70 71 72 setup_gem(GEM_NAME, GEM_VERSION) do |spec| 73 spec.summary = "Mongrel Native Win32 Service Plugin for Rails" 74 spec.description = "This plugin offer native win32 services for rails, powered by Mongrel." 75 spec.author = "Luis Lavena" 76 spec.platform = Gem::Platform::WIN32 77 78 spec.files -= Dir["bin/**/*"] 79 spec.files -= Dir["**/*.{o,a}"] 80 spec.files += Dir["native/**/*.{bas,bi}"] 81 spec.files += ["bin/mongrel_service.exe"] 82 83 spec.add_dependency('gem_plugin', '>= 0.2.1') 84 spec.add_dependency('mongrel', '>= 0.3.14') 85 spec.add_dependency('win32-service', '>= 0.5.0') 86 87 spec.files += Dir.glob("resources/**/*") 88 end 89 90 task :install => [:test, :package] do 91 sh %{gem install pkg/#{name}-#{version}.gem} 92 end 93 94 task :uninstall => [:clean] do 95 sh %{gem uninstall #{name}} 96 end 97 branches/win32-native_service/projects/mongrel_service/lib/mongrel_service/init.rb
r347 r404 4 4 require 'rbconfig' 5 5 require 'win32/service' 6 6 require 'fileutils' 7 7 8 8 module Service … … 27 27 ['-C', '--config PATH', "Use a config file", :@config_file, nil], 28 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 29 ['', '--prefix PATH', "URL prefix for Rails app", :@prefix, nil] 31 30 ] … … 44 43 # start with the premise of app really exist. 45 44 app_exist = true 46 %w{app config db log public}.each do |path|45 %w{app config log}.each do |path| 47 46 if !File.directory?(File.join(@cwd, path)) 48 47 app_exist = false … … 61 60 valid_exists? @config_file, "Config file not there: #@config_file" if @config_file 62 61 63 # Validate the number of cpu to bind to.64 valid? @cpu.to_i > 0, "You must specify a numeric value for cpu. (1..8)" if @cpu65 66 62 # We should validate service existance here, right Zed? 67 63 begin … … 79 75 80 76 def run 77 # check if mongrel_service.exe is in ruby bindir. 78 gem_root = File.join(File.dirname(__FILE__), "..", "..") 79 gem_executable = File.join(gem_root, "bin/mongrel_service.exe") 80 bindir_executable = File.join(Config::CONFIG['bindir'], '/mongrel_service.exe') 81 82 unless File.exist?(bindir_executable) 83 STDERR.puts "** Copying native mongrel_service executable..." 84 FileUtils.cp gem_executable, bindir_executable rescue nil 85 end 86 87 unless FileUtils.compare_file(bindir_executable, gem_executable) 88 STDERR.puts "** Updating native mongrel_service executable..." 89 FileUtils.rm_f bindir_executable rescue nil 90 FileUtils.cp gem_executable, bindir_executable rescue nil 91 end 92 93 # build the command line 94 argv = [] 95 96 # start using the native executable 97 argv << '"' + bindir_executable + '"' 98 99 # use the 'single' service for now 100 argv << "single" 101 81 102 # command line setting override config file settings 82 103 @options = { :host => @address, :port => @port, :cwd => @cwd, … … 85 106 :debug => @debug, :includes => ["mongrel"], :config_script => @config_script, 86 107 :num_procs => @num_procs, :timeout => @timeout, :cpu => @cpu, :prefix => @prefix 108 } 109 110 # if we are using a config file, pass -c and -C to the service instead of each start parameter. 111 if @config_file 112 STDERR.puts "** Using #{@config_file} instead of command line parameters." 113 conf = YAML.load_file(@config_file) 114 115 # add the root folder (-c) 116 argv << "-c \"#{conf[:cwd]}\"" 117 118 # use the config file 119 argv << "-C \"#{@config_file}\"" 87 120 88 } 89 90 if @config_file 91 STDERR.puts "** Loading settings from #{@config_file} (command line options override)." 92 conf = YAML.load_file(@config_file) 93 @options = @options.merge! conf 121 else 122 # use the command line instead 123 # now the options 124 argv << "-e #{@options[:environment]}" if @options[:environment] 125 argv << "-p #{@options[:port]}" 126 argv << "-a #{@options[:host]}" if @options[:host] 127 argv << "-l \"#{@options[:log_file]}\"" if @options[:log_file] 128 argv << "-P \"#{@options[:pid_file]}\"" 129 argv << "-c \"#{@options[:cwd]}\"" if @options[:cwd] 130 argv << "-t #{@options[:timeout]}" if @options[:timeout] 131 argv << "-m \"#{@options[:mime_map]}\"" if @options[:mime_map] 132 argv << "-r \"#{@options[:docroot]}\"" if @options[:docroot] 133 argv << "-n #{@options[:num_procs]}" if @options[:num_procs] 134 argv << "-B" if @options[:debug] 135 argv << "-S \"#{@options[:config_script]}\"" if @options[:config_script] 136 argv << "-u #{@options[:cpu.to_i]}" if @options[:cpu] 137 argv << "--prefix \"#{@options[:prefix]}\"" if @options[:prefix] 94 138 end 95 96 argv = []97 98 # ruby.exe instead of rubyw.exe due a exception raised when stoping the service!99 argv << '"' + Config::CONFIG['bindir'] + '/ruby.exe' + '"'100 101 # add service_script, we now use the rubygem powered one102 argv << '"' + Config::CONFIG['bindir'] + '/mongrel_service' + '"'103 104 # now the options105 argv << "-e #{@options[:environment]}" if @options[:environment]106 argv << "-p #{@options[:port]}"107 argv << "-a #{@options[:host]}" if @options[:host]108 argv << "-l \"#{@options[:log_file]}\"" if @options[:log_file]109 argv << "-P \"#{@options[:pid_file]}\""110 argv << "-c \"#{@options[:cwd]}\"" if @options[:cwd]111 argv << "-t #{@options[:timeout]}" if @options[:timeout]112 argv << "-m \"#{@options[:mime_map]}\"" if @options[:mime_map]113 argv << "-r \"#{@options[:docroot]}\"" if @options[:docroot]114 argv << "-n #{@options[:num_procs]}" if @options[:num_procs]115 argv << "-B" if @options[:debug]116 argv << "-S \"#{@options[:config_script]}\"" if @options[:config_script]117 argv << "-u #{@options[:cpu.to_i]}" if @options[:cpu]118 argv << "--prefix \"#{@options[:prefix]}\"" if @options[:prefix]119 139 120 140 svc = Win32::Service.new … … 125 145 s.binary_path_name = argv.join ' ' 126 146 s.dependencies = [] 147 s.service_type = Win32::Service::WIN32_OWN_PROCESS 127 148 } 128 149 puts "Mongrel service '#{@svc_display}' installed as '#{@svc_name}'." … … 148 169 begin 149 170 valid? Win32::Service.exists?(@svc_name), "There is no service with that name, cannot proceed." 171 Win32::Service.open(@svc_name) do |svc| 172 valid? svc.binary_path_name.include?("mongrel_service"), "The service specified isn't a Mongrel service." 173 end 150 174 rescue 151 175 end … … 173 197 end 174 198 end 175 176 class Start < GemPlugin::Plugin "/commands"177 include Mongrel::Command::Base178 include ServiceValidation179 180 def run181 display_name = Win32::Service.getdisplayname(@svc_name)182 183 begin184 Win32::Service.start(@svc_name)185 started = false186 while started == false187 s = Win32::Service.status(@svc_name)188 started = true if s.current_state == "running"189 break if started == true190 puts "One moment, " + s.current_state191 sleep 1192 end193 puts "#{display_name} service started"194 rescue Win32::ServiceError => err195 puts "There was a problem starting the service:"196 puts err197 end198 end199 end200 201 class Stop < GemPlugin::Plugin "/commands"202 include Mongrel::Command::Base203 include ServiceValidation204 205 def run206 display_name = Win32::Service.getdisplayname(@svc_name)207 208 begin209 Win32::Service.stop(@svc_name)210 stopped = false211 while stopped == false212 s = Win32::Service.status(@svc_name)213 stopped = true if s.current_state == "stopped"214 break if stopped == true215 puts "One moment, " + s.current_state216 sleep 1217 end218 puts "#{display_name} service stopped"219 rescue Win32::ServiceError => err220 puts "There was a problem stopping the service:"221 puts err222 end223 end224 end225 199 end branches/win32-native_service/projects/mongrel_service/native/mongrel_service.bas
r402 r404 31 31 .name = "single" 32 32 .description = "Mongrel Single Process service" 33 34 '# disabling shared process 35 .shared_process = FALSE 33 36 34 37 '# TODO: fix inheritance here
