Module: InternetBoxLogger::Tasks::ElasticSearch
- Defined in:
- lib/tasks/elastic_search.rb
Constant Summary collapse
- ES_PID_FILE =
'/tmp/es.pid'
Instance Method Summary collapse
- #already_running? ⇒ Boolean
- #create_pid_file(pid = nil) ⇒ Object
- #es_binary ⇒ Object
- #es_pid ⇒ Object
- #start_es_server ⇒ Object
- #stop_es_server ⇒ Object
Instance Method Details
#already_running? ⇒ Boolean
15 16 17 |
# File 'lib/tasks/elastic_search.rb', line 15 def already_running? !es_pid.nil? end |
#create_pid_file(pid = nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/tasks/elastic_search.rb', line 26 def create_pid_file(pid=nil) if block_given? File.open(ES_PID_FILE, 'w+') do |f| yield f end pid = es_pid raise "Invalid operation on pid file" if pid.nil? || pid < 1 else raise "Specify a pid or a block !" if pid.nil? raise "Invalid pid!" unless pid.is_a? Fixnum File.open(ES_PID_FILE, 'w+') do |f| f.puts pid end end pid end |
#es_binary ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/tasks/elastic_search.rb', line 7 def es_binary es_bin_from_config = InternetBoxLogger::ElasticSearch::Server.local_path es_bin = File.is_executable? es_bin_from_config raise "Cannot find executable for ElasticSearch with name '#{es_bin_from_config}'. Try setting-up elastic_binary in application config." if es_bin.nil? raise "You have not enough rights to run '#{es_bin_from_config}'." unless es_bin es_bin end |
#es_pid ⇒ Object
19 20 21 22 23 |
# File 'lib/tasks/elastic_search.rb', line 19 def es_pid pid = `ps aux | grep 'elasticsearc[h]' | awk '{ print $2 }'` return nil if pid.nil? || pid.empty? pid.to_i end |
#start_es_server ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/tasks/elastic_search.rb', line 43 def start_es_server if already_running? EasyAppHelper.puts_and_logs 'ElasticSearch already running... Aborting' return nil end spawn("#{es_binary} -d") EasyAppHelper.puts_and_logs 'ElasticSearch server started' true end |
#stop_es_server ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tasks/elastic_search.rb', line 53 def stop_es_server unless already_running? EasyAppHelper.puts_and_logs 'ElasticSearch is not running... Nothing to stop' return nil end pid = es_pid raise 'Invalid operation on pid file' if pid.nil? || pid < 1 Process.kill('SIGTERM', pid) EasyAppHelper.puts_and_logs 'ElasticSearch stopped' true end |