1 # Ferret Win32 Service Daemon, called by Win 32 service,
2 # created by Herryanto Siatono <herryanto@pluitsolutions.com>
4 # see doc/README.win32 for usage instructions
7 require 'win32/service'
12 ARGV.options do |opts|
13 opts.banner = 'Usage: ferret_daemon [options]'
14 opts.on("-l", "--log FILE", "Daemon log file") {|file| options[:log] = file }
15 opts.on("-c","--console","Run Ferret server on console.") {options[:console] = true}
16 opts.on_tail("-h","--help", "Show this help message") {puts opts; exit}
17 opts.on("-e", "--environment ENV ", "Rails environment") {|env|
18 options[:environment] = env
19 ENV['RAILS_ENV'] = env
24 require File.dirname(__FILE__) + '/../config/environment'
26 # Ferret Win32 Service Daemon, called by Win 32 service,
27 # to run on the console, use -c or --console option.
29 class FerretDaemon < Daemon
30 # Standard logger to redirect STDOUT and STDERR to a log file
31 class FerretStandardLogger
32 def initialize(logger)
41 def initialize(options={})
46 @logger = Logger.new @options[:log]
48 @logger = Logger.new RAILS_ROOT + "/log/ferret_service_#{RAILS_ENV}.log"
51 # redirect stout and stderr to Ferret logger if running as windows service
52 $stdout = $stderr = FerretStandardLogger.new(@logger) unless @options[:console]
54 log "Initializing FerretDaemon..."
62 log "Service main enterred..."
69 log "Service main exit..."
73 log "Starting Ferret DRb server..."
74 ActsAsFerret::Remote::Server.start
75 log "FerretDaemon started."
79 log "Stopping service..."
81 log "FerretDaemon stopped."
86 puts msg if @options[:console]
92 d = Ferret::FerretDaemon.new(options)