cirandas.net

ref: master

plugins/elasticsearch/Rakefile


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env rake

require 'open-uri'

desc "download elasticsearch"
task :download do
  unless File.exists? '/tmp/elasticsearch.deb'
    puts "downloading elasticsearch Debian package..."
    download = open('https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.5.deb')
    IO.copy_stream(download, '/tmp/elasticsearch.deb')
  end
end

desc "install elasticsearch"
task :install => :download do
  sh 'sudo apt-get install openjdk-7-jdk'
  sh 'sudo dpkg -i /tmp/elasticsearch.deb || sudo apt-get install -f'
end

desc "start elasticsearch"
task :start do
  if not system 'sudo systemctl start elasticsearch > /dev/null'
    Rake::Task['install'].invoke
  end
  puts "Enable Elasticsearch service"
  sh 'sudo systemctl start elasticsearch >> /dev/null 2>&1'
  sh 'sudo systemctl enable elasticsearch  >> /dev/null 2>&1'
  sleep 10
end

desc "stop elasticsearch"
task :stop do
  puts "Disable elasticsearch service"
  sh 'sudo systemctl stop elasticsearch >> /dev/null 2>&1'
  sh 'sudo systemctl disable elasticsearch >> /dev/null 2>&1'
end