Changeset 404

Show
Ignore:
Timestamp:
11/20/06 22:06:45 (2 years ago)
Author:
luislavena
Message:

Adjustments to Rakefile (win32 platform specific).
Disable process sharing for single service (taking in consideration addition of cluster).
Removed mongrel_service script from bin.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/win32-native_service/projects/mongrel_service/Rakefile

    r402 r404  
    1717task :default => [:test, :compile, :package] 
    1818 
    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  
     19GEM_VERSION = "0.3.0" 
     20GEM_NAME = "mongrel_service" 
    4621 
    4722# ServiceFB namespace (lib) 
     
    9368task :compile => "native:build" 
    9469task :clobber => "native:clobber" 
     70 
     71 
     72setup_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/**/*") 
     88end 
     89 
     90task :install => [:test, :package] do 
     91  sh %{gem install pkg/#{name}-#{version}.gem} 
     92end 
     93 
     94task :uninstall => [:clean] do 
     95  sh %{gem uninstall #{name}} 
     96end 
     97 
  • branches/win32-native_service/projects/mongrel_service/lib/mongrel_service/init.rb

    r347 r404  
    44require 'rbconfig' 
    55require 'win32/service' 
    6  
     6require 'fileutils' 
    77 
    88module Service 
     
    2727          ['-C', '--config PATH', "Use a config file", :@config_file, nil], 
    2828          ['-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], 
    3029          ['', '--prefix PATH', "URL prefix for Rails app", :@prefix, nil] 
    3130        ] 
     
    4443      # start with the premise of app really exist. 
    4544      app_exist = true 
    46       %w{app config db log public}.each do |path| 
     45      %w{app config log}.each do |path| 
    4746        if !File.directory?(File.join(@cwd, path)) 
    4847          app_exist = false 
     
    6160      valid_exists? @config_file, "Config file not there: #@config_file" if @config_file 
    6261 
    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 @cpu 
    65        
    6662      # We should validate service existance here, right Zed? 
    6763      begin 
     
    7975     
    8076    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       
    81102      # command line setting override config file settings 
    82103      @options = { :host => @address,  :port => @port, :cwd => @cwd, 
     
    85106        :debug => @debug, :includes => ["mongrel"], :config_script => @config_script, 
    86107        :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}\"" 
    87120 
    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] 
    94138      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 one 
    102       argv << '"' + Config::CONFIG['bindir'] + '/mongrel_service' + '"' 
    103  
    104       # now the options 
    105       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] 
    119139 
    120140      svc = Win32::Service.new 
     
    125145          s.binary_path_name = argv.join ' ' 
    126146          s.dependencies     = [] 
     147          s.service_type     = Win32::Service::WIN32_OWN_PROCESS 
    127148        } 
    128149        puts "Mongrel service '#{@svc_display}' installed as '#{@svc_name}'." 
     
    148169      begin 
    149170        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 
    150174      rescue 
    151175      end 
     
    173197    end 
    174198  end 
    175  
    176   class Start < GemPlugin::Plugin "/commands" 
    177     include Mongrel::Command::Base 
    178     include ServiceValidation 
    179      
    180     def run 
    181       display_name = Win32::Service.getdisplayname(@svc_name) 
    182    
    183       begin 
    184         Win32::Service.start(@svc_name) 
    185         started = false 
    186         while started == false 
    187           s = Win32::Service.status(@svc_name) 
    188           started = true if s.current_state == "running" 
    189           break if started == true 
    190           puts "One moment, " + s.current_state 
    191           sleep 1 
    192         end 
    193         puts "#{display_name} service started" 
    194       rescue Win32::ServiceError => err 
    195         puts "There was a problem starting the service:" 
    196         puts err 
    197       end 
    198     end 
    199   end 
    200  
    201   class Stop < GemPlugin::Plugin "/commands" 
    202     include Mongrel::Command::Base 
    203     include ServiceValidation 
    204      
    205     def run 
    206       display_name = Win32::Service.getdisplayname(@svc_name) 
    207    
    208       begin 
    209         Win32::Service.stop(@svc_name) 
    210         stopped = false 
    211         while stopped == false 
    212           s = Win32::Service.status(@svc_name) 
    213           stopped = true if s.current_state == "stopped" 
    214           break if stopped == true 
    215           puts "One moment, " + s.current_state 
    216           sleep 1 
    217         end 
    218         puts "#{display_name} service stopped" 
    219       rescue Win32::ServiceError => err 
    220         puts "There was a problem stopping the service:" 
    221         puts err 
    222       end 
    223     end 
    224   end 
    225199end 
  • branches/win32-native_service/projects/mongrel_service/native/mongrel_service.bas

    r402 r404  
    3131            .name = "single" 
    3232            .description = "Mongrel Single Process service" 
     33             
     34            '# disabling shared process 
     35            .shared_process = FALSE 
    3336             
    3437            '# TODO: fix inheritance here