acts_as_ferret 0.4.1 → 0.4.2
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/README +3 -0
- data/bin/aaf_install +23 -0
- data/config/ferret_server.yml +19 -8
- data/doc/README.win32 +23 -0
- data/doc/monit-example +22 -0
- data/install.rb +1 -2
- data/lib/act_methods.rb +16 -4
- data/lib/acts_as_ferret.rb +14 -23
- data/lib/bulk_indexer.rb +35 -0
- data/lib/class_methods.rb +192 -49
- data/lib/ferret_extensions.rb +52 -18
- data/lib/ferret_server.rb +109 -37
- data/lib/instance_methods.rb +45 -15
- data/lib/local_index.rb +7 -5
- data/lib/search_results.rb +53 -0
- data/lib/server_manager.rb +44 -0
- data/lib/shared_index_class_methods.rb +1 -1
- data/lib/unix_daemon.rb +63 -0
- data/rakefile +5 -2
- data/script/ferret_daemon +94 -0
- data/script/ferret_server +1 -17
- data/script/ferret_service +178 -0
- metadata +34 -26
- data/script/ferret_start +0 -72
- data/script/ferret_stop +0 -26
@@ -0,0 +1,94 @@
|
|
1
|
+
# Ferret Win32 Service Daemon, called by Win 32 service,
|
2
|
+
# created by Herryanto Siatono <herryanto@pluitsolutions.com>
|
3
|
+
#
|
4
|
+
# see doc/README.win32 for usage instructions
|
5
|
+
#
|
6
|
+
require 'optparse'
|
7
|
+
require 'win32/service'
|
8
|
+
include Win32
|
9
|
+
|
10
|
+
# Read options
|
11
|
+
options = {}
|
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
|
20
|
+
}
|
21
|
+
opts.parse!
|
22
|
+
end
|
23
|
+
|
24
|
+
require File.dirname(__FILE__) + '/../config/environment'
|
25
|
+
|
26
|
+
# Ferret Win32 Service Daemon, called by Win 32 service,
|
27
|
+
# to run on the console, use -c or --console option.
|
28
|
+
module Ferret
|
29
|
+
class FerretDaemon < Daemon
|
30
|
+
# Standard logger to redirect STDOUT and STDERR to a log file
|
31
|
+
class FerretStandardLogger
|
32
|
+
def initialize(logger)
|
33
|
+
@logger = logger
|
34
|
+
end
|
35
|
+
|
36
|
+
def write(s)
|
37
|
+
@logger.info s
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize(options={})
|
42
|
+
@options = options
|
43
|
+
|
44
|
+
# initialize logger
|
45
|
+
if options[:log]
|
46
|
+
@logger = Logger.new @options[:log]
|
47
|
+
else
|
48
|
+
@logger = Logger.new RAILS_ROOT + "/log/ferret_service_#{RAILS_ENV}.log"
|
49
|
+
end
|
50
|
+
|
51
|
+
# redirect stout and stderr to Ferret logger if running as windows service
|
52
|
+
$stdout = $stderr = FerretStandardLogger.new(@logger) unless @options[:console]
|
53
|
+
|
54
|
+
log "Initializing FerretDaemon..."
|
55
|
+
if @options[:console]
|
56
|
+
self.service_init
|
57
|
+
self.service_main
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def service_main
|
62
|
+
log "Service main enterred..."
|
63
|
+
|
64
|
+
while running?
|
65
|
+
log "Listening..."
|
66
|
+
sleep
|
67
|
+
end
|
68
|
+
|
69
|
+
log "Service main exit..."
|
70
|
+
end
|
71
|
+
|
72
|
+
def service_init
|
73
|
+
log "Starting Ferret DRb server..."
|
74
|
+
ActsAsFerret::Remote::Server.start
|
75
|
+
log "FerretDaemon started."
|
76
|
+
end
|
77
|
+
|
78
|
+
def service_stop
|
79
|
+
log "Stopping service..."
|
80
|
+
DRb.stop_service
|
81
|
+
log "FerretDaemon stopped."
|
82
|
+
end
|
83
|
+
|
84
|
+
def log(msg)
|
85
|
+
@logger.info msg
|
86
|
+
puts msg if @options[:console]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
if __FILE__ == $0
|
92
|
+
d = Ferret::FerretDaemon.new(options)
|
93
|
+
d.mainloop
|
94
|
+
end
|
data/script/ferret_server
CHANGED
@@ -1,18 +1,2 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# Ferret DRb server launcher script
|
4
|
-
#
|
5
|
-
# Place doc/ferret_server.yml into RAILS_ROOT/config and fit to taste.
|
6
|
-
#
|
7
|
-
# Start this script with script/runner and RAILS_ENV set.
|
8
|
-
#
|
9
|
-
# to run the unit tests against the drb server, start it with
|
10
|
-
# RAILS_ENV=test script/runner script/ferret_server
|
11
|
-
# and run your tests with the AAF_REMOTE environment variable set to a
|
12
|
-
# non-empty value
|
13
|
-
|
14
|
-
|
15
|
-
ActsAsFerret::Remote::Server.start
|
16
|
-
DRb.thread.join
|
17
|
-
|
18
|
-
|
2
|
+
require File.join(File.dirname(__FILE__), '../vendor/plugins/acts_as_ferret/lib/server_manager')
|
@@ -0,0 +1,178 @@
|
|
1
|
+
# Ferret Win32 Service Daemon install script
|
2
|
+
# created by Herryanto Siatono <herryanto@pluitsolutions.com>
|
3
|
+
#
|
4
|
+
# see doc/README.win32 for usage instructions
|
5
|
+
#
|
6
|
+
require 'optparse'
|
7
|
+
require 'win32/service'
|
8
|
+
include Win32
|
9
|
+
|
10
|
+
module Ferret
|
11
|
+
# Parse and validate service command and options
|
12
|
+
class FerretServiceCommand
|
13
|
+
COMMANDS = ['install', 'remove', 'start', 'stop', 'help']
|
14
|
+
BANNER = "Usage: ruby script/ferret_service <command> [options]"
|
15
|
+
|
16
|
+
attr_reader :options, :command
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@options = {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def valid_command?
|
23
|
+
COMMANDS.include?@command
|
24
|
+
end
|
25
|
+
|
26
|
+
def valid_options?
|
27
|
+
@options[:name] and !@options[:name].empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def print_command_list
|
31
|
+
puts BANNER
|
32
|
+
puts "\nAvailable commands:\n"
|
33
|
+
puts COMMANDS.map {|cmd| " - #{cmd}\n"}
|
34
|
+
puts "\nUse option -h for each command to help."
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
|
38
|
+
def validate_options
|
39
|
+
errors = []
|
40
|
+
errors << "Service name is required." unless @options[:name]
|
41
|
+
|
42
|
+
if (errors.size > 0)
|
43
|
+
errors << "Error found. Use: 'ruby script/ferret_service #{@command} -h' for to get help."
|
44
|
+
puts errors.join("\n")
|
45
|
+
exit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def run(args)
|
50
|
+
@command = args.shift
|
51
|
+
@command = @command.dup.downcase if @command
|
52
|
+
|
53
|
+
# validate command and options
|
54
|
+
print_command_list unless valid_command? or @command == 'help'
|
55
|
+
|
56
|
+
opts_parser = create_options_parser
|
57
|
+
begin
|
58
|
+
opts_parser.parse!(args)
|
59
|
+
rescue OptionParser::ParseError => e
|
60
|
+
puts e
|
61
|
+
puts opts_parser
|
62
|
+
end
|
63
|
+
|
64
|
+
# validate required options
|
65
|
+
validate_options
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_options_parser
|
69
|
+
opts_parser = OptionParser.new
|
70
|
+
opts_parser.banner = BANNER
|
71
|
+
opts_parser.on("-n", "--name=NAME", "Service name") {|name| @options[:name] = name }
|
72
|
+
opts_parser.on_tail("-t", "--trace", "Display stack trace when exception thrown") { @options[:trace] = true }
|
73
|
+
opts_parser.on_tail("-h", "--help", "Show this help message") { puts opts_parser; exit }
|
74
|
+
|
75
|
+
if ['install'].include?@command
|
76
|
+
opts_parser.on("-d", "--display=NAME", "Service display name") {|name| @options[:display] = name }
|
77
|
+
|
78
|
+
opts_parser.on("-l", "--log FILE", "Service log file") {|file| @options[:log] = file }
|
79
|
+
opts_parser.on("-e", "--environment ENV ", "Rails environment") { |env|
|
80
|
+
@options[:environment] = env
|
81
|
+
ENV['RAILS_ENV'] = env
|
82
|
+
}
|
83
|
+
end
|
84
|
+
opts_parser
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
# Install, Remove, Start and Stop Ferret DRb server Win32 service
|
89
|
+
class FerretService
|
90
|
+
FERRET_DAEMON = 'ferret_daemon'
|
91
|
+
|
92
|
+
def initialize
|
93
|
+
end
|
94
|
+
|
95
|
+
def install
|
96
|
+
svc = Service.new
|
97
|
+
|
98
|
+
begin
|
99
|
+
if Service.exists?(@options[:name])
|
100
|
+
puts "Service name '#{@options[:name]}' already exists."
|
101
|
+
return
|
102
|
+
end
|
103
|
+
|
104
|
+
svc.create_service do |s|
|
105
|
+
s.service_name = @options[:name]
|
106
|
+
s.display_name = @options[:display]
|
107
|
+
s.binary_path_name = binary_path_name
|
108
|
+
s.dependencies = []
|
109
|
+
end
|
110
|
+
|
111
|
+
svc.close
|
112
|
+
puts "'#{@options[:name]}' service installed."
|
113
|
+
rescue => e
|
114
|
+
handle_error(e)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def remove
|
119
|
+
begin
|
120
|
+
Service.stop(@options[:name])
|
121
|
+
rescue
|
122
|
+
end
|
123
|
+
|
124
|
+
begin
|
125
|
+
Service.delete(@options[:name])
|
126
|
+
puts "'#{@options[:name]}' service removed."
|
127
|
+
rescue => e
|
128
|
+
handle_error(e)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def start
|
133
|
+
begin
|
134
|
+
Service.start(@options[:name])
|
135
|
+
puts "'#{@options[:name]}' successfully started."
|
136
|
+
rescue => e
|
137
|
+
handle_error(e)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def stop
|
142
|
+
begin
|
143
|
+
Service.stop(@options[:name])
|
144
|
+
puts "'#{@options[:name]}' successfully stopped.\n"
|
145
|
+
rescue => e
|
146
|
+
handle_error(e)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def run(args)
|
151
|
+
svc_cmd = FerretServiceCommand.new
|
152
|
+
svc_cmd.run(args)
|
153
|
+
@options = svc_cmd.options
|
154
|
+
self.send(svc_cmd.command.to_sym)
|
155
|
+
end
|
156
|
+
|
157
|
+
protected
|
158
|
+
def handle_error(e)
|
159
|
+
if @options[:trace]
|
160
|
+
raise e
|
161
|
+
else
|
162
|
+
puts e
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def binary_path_name
|
167
|
+
path = ""
|
168
|
+
path << "#{ENV['RUBY_HOME']}/bin/" if ENV['RUBY_HOME']
|
169
|
+
path << "ruby.exe "
|
170
|
+
path << File.expand_path("script/" + FERRET_DAEMON)
|
171
|
+
path << " -e #{@options[:environment]} " if @options[:environment]
|
172
|
+
path << " -l #{@options[:log]} " if @options[:log]
|
173
|
+
path
|
174
|
+
end
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
Ferret::FerretService.new.run(ARGV)
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: acts_as_ferret
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.
|
7
|
-
date: 2007-
|
6
|
+
version: 0.4.2
|
7
|
+
date: 2007-11-18 00:00:00 +01:00
|
8
8
|
summary: acts_as_ferret - Ferret based full text search for any ActiveRecord model
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -13,7 +13,7 @@ homepage: http://projects.jkraemer.net/acts_as_ferret
|
|
13
13
|
rubyforge_project:
|
14
14
|
description:
|
15
15
|
autorequire: acts_as_ferret
|
16
|
-
default_executable:
|
16
|
+
default_executable: aaf_install
|
17
17
|
bindir: bin
|
18
18
|
has_rdoc: true
|
19
19
|
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
@@ -29,42 +29,50 @@ post_install_message:
|
|
29
29
|
authors:
|
30
30
|
- Jens Kraemer
|
31
31
|
files:
|
32
|
-
- script
|
33
|
-
- config
|
34
|
-
- doc
|
35
32
|
- lib
|
36
|
-
- LICENSE
|
37
|
-
- rakefile
|
38
|
-
- init.rb
|
39
|
-
- install.rb
|
40
|
-
- README
|
41
|
-
- script/ferret_start
|
42
|
-
- script/ferret_stop
|
43
|
-
- script/ferret_server
|
44
|
-
- config/ferret_server.yml
|
45
|
-
- lib/ferret_server.rb
|
46
|
-
- lib/more_like_this.rb
|
47
|
-
- lib/shared_index.rb
|
48
33
|
- lib/ferret_cap_tasks.rb
|
49
|
-
- lib/local_index.rb
|
50
|
-
- lib/multi_index.rb
|
51
|
-
- lib/remote_index.rb
|
52
34
|
- lib/acts_as_ferret.rb
|
53
|
-
- lib/
|
54
|
-
- lib/shared_index_class_methods.rb
|
35
|
+
- lib/multi_index.rb
|
55
36
|
- lib/ferret_extensions.rb
|
56
|
-
- lib/
|
37
|
+
- lib/more_like_this.rb
|
57
38
|
- lib/instance_methods.rb
|
58
39
|
- lib/class_methods.rb
|
40
|
+
- lib/ferret_server.rb
|
41
|
+
- lib/shared_index.rb
|
42
|
+
- lib/local_index.rb
|
43
|
+
- lib/remote_index.rb
|
44
|
+
- lib/index.rb
|
59
45
|
- lib/act_methods.rb
|
46
|
+
- lib/shared_index_class_methods.rb
|
47
|
+
- lib/ferret_result.rb
|
48
|
+
- lib/search_results.rb
|
49
|
+
- lib/bulk_indexer.rb
|
50
|
+
- lib/server_manager.rb
|
51
|
+
- lib/unix_daemon.rb
|
52
|
+
- LICENSE
|
53
|
+
- rakefile
|
54
|
+
- init.rb
|
55
|
+
- README
|
56
|
+
- script
|
57
|
+
- script/ferret_daemon
|
58
|
+
- script/ferret_service
|
59
|
+
- script/ferret_server
|
60
|
+
- doc
|
61
|
+
- doc/monit-example
|
62
|
+
- doc/README.win32
|
63
|
+
- config
|
64
|
+
- config/ferret_server.yml
|
65
|
+
- install.rb
|
66
|
+
- bin
|
67
|
+
- bin/aaf_install
|
60
68
|
test_files: []
|
61
69
|
|
62
70
|
rdoc_options: []
|
63
71
|
|
64
72
|
extra_rdoc_files: []
|
65
73
|
|
66
|
-
executables:
|
67
|
-
|
74
|
+
executables:
|
75
|
+
- aaf_install
|
68
76
|
extensions: []
|
69
77
|
|
70
78
|
requirements: []
|
data/script/ferret_start
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# Ferret DRb server launcher script
|
3
|
-
#
|
4
|
-
# Place doc/ferret_server.yml into RAILS_ROOT/config and fit to taste. Start
|
5
|
-
# it with RAILS_ENV set to the desired environment.
|
6
|
-
#
|
7
|
-
#
|
8
|
-
# To run the demo project's unit tests against the drb server, start it with
|
9
|
-
#
|
10
|
-
# RAILS_ENV=test script/ferret_start
|
11
|
-
#
|
12
|
-
# and run your tests with the AAF_REMOTE environment variable set to a
|
13
|
-
# non-empty value:
|
14
|
-
#
|
15
|
-
# AAF_REMOTE=true rake
|
16
|
-
#
|
17
|
-
# The server writes a log file in log/ferret_server.log, it's
|
18
|
-
# STDOUT gets redirected to log/ferret_server.out
|
19
|
-
|
20
|
-
ENV['FERRET_USE_LOCAL_INDEX'] = 'true'
|
21
|
-
require File.dirname(__FILE__) + '/../config/boot'
|
22
|
-
require RAILS_ROOT + '/config/environment'
|
23
|
-
|
24
|
-
|
25
|
-
config = ActsAsFerret::Remote::Config.load
|
26
|
-
@pid_file = config['pid_file']
|
27
|
-
|
28
|
-
def write_pid_file
|
29
|
-
raise "No PID file defined" if @pid_file.blank?
|
30
|
-
open(@pid_file,"w") {|f| f.write(Process.pid) }
|
31
|
-
end
|
32
|
-
|
33
|
-
def safefork
|
34
|
-
tryagain = true
|
35
|
-
|
36
|
-
while tryagain
|
37
|
-
tryagain = false
|
38
|
-
begin
|
39
|
-
if pid = fork
|
40
|
-
return pid
|
41
|
-
end
|
42
|
-
rescue Errno::EWOULDBLOCK
|
43
|
-
sleep 5
|
44
|
-
tryagain = true
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
safefork and exit
|
50
|
-
at_exit do
|
51
|
-
File.unlink(@pid_file) if @pid_file && File.exists?(@pid_file) && File.read(@pid_file).to_i == Process.pid
|
52
|
-
end
|
53
|
-
print "Starting ferret DRb server..."
|
54
|
-
trap("TERM") { exit(0) }
|
55
|
-
sess_id = Process.setsid
|
56
|
-
|
57
|
-
|
58
|
-
begin
|
59
|
-
ActsAsFerret::Remote::Server.start
|
60
|
-
write_pid_file
|
61
|
-
puts "Done."
|
62
|
-
STDIN.reopen "/dev/null" # Free file descriptors and
|
63
|
-
STDOUT.reopen "#{RAILS_ROOT}/log/ferret_server.out", "a" # point them somewhere sensible
|
64
|
-
STDERR.reopen STDOUT # STDOUT/STDERR should go to a logfile
|
65
|
-
rescue
|
66
|
-
$stderr.puts "Error starting ferret DRb server: #{$!}"
|
67
|
-
$stderr.puts $!.backtrace
|
68
|
-
exit(1)
|
69
|
-
end
|
70
|
-
DRb.thread.join
|
71
|
-
|
72
|
-
# vim:set filetype=ruby:
|
data/script/ferret_stop
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
#!/usr/bin/env script/runner
|
2
|
-
|
3
|
-
config = ActsAsFerret::Remote::Config.load
|
4
|
-
|
5
|
-
def send_signal(signal, pid_file)
|
6
|
-
pid = open(pid_file).read.to_i
|
7
|
-
print "Sending #{signal} to ferret_server with PID #{pid}..."
|
8
|
-
begin
|
9
|
-
Process.kill(signal, pid)
|
10
|
-
rescue Errno::ESRCH
|
11
|
-
puts "Process does not exist. Not running. Removing stale pid file anyway."
|
12
|
-
File.unlink(pid_file)
|
13
|
-
end
|
14
|
-
|
15
|
-
puts "Done."
|
16
|
-
end
|
17
|
-
|
18
|
-
pid_file = config['pid_file']
|
19
|
-
puts "Stopping ferret_server..."
|
20
|
-
if File.file?(pid_file)
|
21
|
-
send_signal("TERM", pid_file)
|
22
|
-
else
|
23
|
-
puts "no pid file found"
|
24
|
-
end
|
25
|
-
|
26
|
-
# vim:set filetype=ruby:
|