|
10 | 10 | #
|
11 | 11 | # * Git
|
12 | 12 | # * Ruby >= 1.9.3
|
13 |
| -# * Rails >= 4 |
14 |
| -# * Java >= 7 (for Elasticsearch) |
| 13 | +# * Rails >= 5 |
| 14 | +# * Java >= 8 (for Elasticsearch) |
15 | 15 | #
|
16 | 16 | # Usage:
|
17 | 17 | # ------
|
|
31 | 31 | end
|
32 | 32 | end
|
33 | 33 |
|
34 |
| -run "touch tmp/.gitignore" |
35 |
| - |
36 |
| -append_to_file ".gitignore", "vendor/elasticsearch-1.0.1/\n" |
| 34 | +$elasticsearch_url = ENV.fetch('ELASTICSEARCH_URL', 'http://localhost:9200') |
37 | 35 |
|
38 |
| -git :init |
39 |
| -git add: "." |
40 |
| -git commit: "-m 'Initial commit: Clean application'" |
| 36 | +# ----- Check & download Elasticsearch ------------------------------------------------------------ |
41 | 37 |
|
42 |
| -# ----- Download Elasticsearch -------------------------------------------------------------------- |
| 38 | +cluster_info = Net::HTTP.get(URI.parse($elasticsearch_url)) rescue nil |
| 39 | +cluster_info = JSON.parse(cluster_info) if cluster_info |
43 | 40 |
|
44 |
| -ELASTICSEARCH_URL = ENV.fetch('ELASTICSEARCH_URL', 'http://localhost:9200') |
| 41 | +if cluster_info.nil? || cluster_info['version']['number'] < '5' |
| 42 | + # Change the port when incompatible Elasticsearch version is running on localhost:9200 |
| 43 | + if $elasticsearch_url == 'http://localhost:9200' && cluster_info && cluster_info['version']['number'] < '5' |
| 44 | + $change_port = '9280' |
| 45 | + $elasticsearch_url = "http://localhost:#{$change_port}" |
| 46 | + end |
45 | 47 |
|
46 |
| -unless (Net::HTTP.get(URI.parse(ELASTICSEARCH_URL)) rescue false) |
47 | 48 | COMMAND = <<-COMMAND.gsub(/^ /, '')
|
48 |
| - curl -# -O "http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.0.1.tar.gz" |
49 |
| - tar -zxf elasticsearch-1.0.1.tar.gz |
50 |
| - rm -f elasticsearch-1.0.1.tar.gz |
51 |
| - ./elasticsearch-1.0.1/bin/elasticsearch -d -p #{destination_root}/tmp/pids/elasticsearch.pid |
| 49 | + curl -# -O "https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.2.1.tar.gz" |
| 50 | + tar -zxf elasticsearch-5.2.1.tar.gz |
| 51 | + rm -f elasticsearch-5.2.1.tar.gz |
| 52 | + ./elasticsearch-5.2.1/bin/elasticsearch -d -p #{destination_root}/tmp/pids/elasticsearch.pid #{$change_port.nil? ? '' : "-E http.port=#{$change_port}" } |
52 | 53 | COMMAND
|
53 | 54 |
|
54 | 55 | puts "\n"
|
55 | 56 | say_status "ERROR", "Elasticsearch not running!\n", :red
|
56 | 57 | puts '-'*80
|
57 |
| - say_status '', "It appears that Elasticsearch is not running on this machine." |
58 |
| - say_status '', "Is it installed? Do you want me to install it for you with this command?\n\n" |
| 58 | + say_status '', "It appears that Elasticsearch 5 is not running on this machine." |
| 59 | + say_status '', "Is it installed? Do you want me to install and run it for you with this command?\n\n" |
59 | 60 | COMMAND.each_line { |l| say_status '', "$ #{l}" }
|
60 | 61 | puts
|
61 | 62 | say_status '', "(To uninstall, just remove the generated application directory.)"
|
|
65 | 66 | puts
|
66 | 67 | say_status "Install", "Elasticsearch", :yellow
|
67 | 68 |
|
| 69 | + java_info = `java -version 2>&1` |
| 70 | + |
| 71 | + unless java_info.match /1\.[8-9]/ |
| 72 | + puts |
| 73 | + say_status "ERROR", "Required Java version (1.8) not found, exiting...", :red |
| 74 | + exit(1) |
| 75 | + end |
| 76 | + |
68 | 77 | commands = COMMAND.split("\n")
|
69 | 78 | exec = commands.pop
|
70 | 79 | inside("vendor") do
|
71 | 80 | commands.each { |command| run command }
|
72 | 81 | run "(#{exec})" # Launch Elasticsearch in subshell
|
73 | 82 | end
|
| 83 | + |
| 84 | + # Wait for Elasticsearch to be up... |
| 85 | + # |
| 86 | + system <<-COMMAND |
| 87 | + until $(curl --silent --head --fail #{$elasticsearch_url} > /dev/null 2>&1); do |
| 88 | + printf '.'; sleep 1 |
| 89 | + done |
| 90 | + COMMAND |
74 | 91 | end
|
75 | 92 | end unless ENV['RAILS_NO_ES_INSTALL']
|
76 | 93 |
|
| 94 | +# ----- Application skeleton ---------------------------------------------------------------------- |
| 95 | + |
| 96 | +run "touch tmp/.gitignore" |
| 97 | + |
| 98 | +append_to_file ".gitignore", "vendor/elasticsearch-5.2.1/\n" |
| 99 | + |
| 100 | +git :init |
| 101 | +git add: "." |
| 102 | +git commit: "-m 'Initial commit: Clean application'" |
| 103 | + |
77 | 104 | # ----- Add README --------------------------------------------------------------------------------
|
78 | 105 |
|
79 | 106 | puts
|
|
0 commit comments