vendor/riddle/lib/riddle/controller.rb in freelancing-god-thinking-sphinx-1.2.4 vs vendor/riddle/lib/riddle/controller.rb in freelancing-god-thinking-sphinx-1.2.5
- old
+ new
@@ -2,43 +2,49 @@
class Controller
def initialize(configuration, path)
@configuration = configuration
@path = path
end
-
+
def index
cmd = "indexer --config #{@path} --all"
cmd << " --rotate" if running?
`#{cmd}`
end
def start
return if running?
cmd = "searchd --pidfile --config #{@path}"
- `#{cmd}`
+ cmd = "start /B #{cmd}" if RUBY_PLATFORM =~ /mswin/
+ `#{cmd}`
sleep(1)
unless running?
puts "Failed to start searchd daemon. Check #{@configuration.searchd.log}."
end
end
def stop
return unless running?
- `kill #{pid}`
+ Process.kill('SIGTERM', pid.to_i)
+ rescue Errno::EINVAL
+ Process.kill('SIGKILL', pid.to_i)
end
def pid
- if File.exists?("#{@configuration.searchd.pid_file}")
- `cat #{@configuration.searchd.pid_file}`[/\d+/]
+ if File.exists?(@configuration.searchd.pid_file)
+ File.read(@configuration.searchd.pid_file)[/\d+/]
else
nil
end
end
def running?
- pid && `ps #{pid} | wc -l`.to_i > 1
+ !!pid && !!Process.kill(0, pid.to_i)
+ rescue
+ false
end
+
end
end
\ No newline at end of file