blob: 79f67a0179b83eb6562045ea1819886c39026508 [file] [log] [blame]
Sean Daguef8b4f852015-02-04 15:46:03 -05001#!/bin/bash -xe
2
3# basic reference point for things like filecache
4#
5# TODO(sdague): once we have a few of these I imagine the download
6# step can probably be factored out to something nicer
7TOP_DIR=$(cd $(dirname "$0")/.. && pwd)
8FILES=$TOP_DIR/files
9source $TOP_DIR/functions
Wayne Okumadd622932015-03-31 00:28:39 -070010DEST=${DEST:-/opt/stack}
11source $TOP_DIR/lib/infra
Sean Daguef8b4f852015-02-04 15:46:03 -050012
13# Package source and version, all pkg files are expected to have
14# something like this, as well as a way to override them.
15ELASTICSEARCH_VERSION=${ELASTICSEARCH_VERSION:-1.4.2}
16ELASTICSEARCH_BASEURL=${ELASTICSEARCH_BASEURL:-https://download.elasticsearch.org/elasticsearch/elasticsearch}
17
18# Elastic search actual implementation
19function wget_elasticsearch {
20 local file=${1}
21
22 if [ ! -f ${FILES}/${file} ]; then
23 wget $ELASTICSEARCH_BASEURL/${file} -O ${FILES}/${file}
24 fi
25
26 if [ ! -f ${FILES}/${file}.sha1.txt ]; then
27 wget $ELASTICSEARCH_BASEURL/${file}.sha1.txt -O ${FILES}/${file}.sha1.txt
28 fi
29
30 pushd ${FILES}; sha1sum ${file} > ${file}.sha1.gen; popd
31
32 if ! diff ${FILES}/${file}.sha1.gen ${FILES}/${file}.sha1.txt; then
33 echo "Invalid elasticsearch download. Could not install."
34 return 1
35 fi
36 return 0
37}
38
39function download_elasticsearch {
40 if is_ubuntu; then
41 wget_elasticsearch elasticsearch-${ELASTICSEARCH_VERSION}.deb
42 elif is_fedora; then
43 wget_elasticsearch elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm
44 fi
45}
46
47function configure_elasticsearch {
48 # currently a no op
Attila Fazekas99b59882015-02-24 12:15:21 +010049 :
Sean Daguef8b4f852015-02-04 15:46:03 -050050}
51
gordon chung76e724b2015-02-11 18:28:37 -050052function _check_elasticsearch_ready {
53 # poll elasticsearch to see if it's started
54 if ! wait_for_service 30 http://localhost:9200; then
55 die $LINENO "Maximum timeout reached. Could not connect to ElasticSearch"
56 fi
57}
58
Sean Daguef8b4f852015-02-04 15:46:03 -050059function start_elasticsearch {
60 if is_ubuntu; then
61 sudo /etc/init.d/elasticsearch start
gordon chung76e724b2015-02-11 18:28:37 -050062 _check_elasticsearch_ready
Sean Daguef8b4f852015-02-04 15:46:03 -050063 elif is_fedora; then
64 sudo /bin/systemctl start elasticsearch.service
gordon chung76e724b2015-02-11 18:28:37 -050065 _check_elasticsearch_ready
Sean Daguef8b4f852015-02-04 15:46:03 -050066 else
67 echo "Unsupported architecture...can not start elasticsearch."
68 fi
69}
70
71function stop_elasticsearch {
72 if is_ubuntu; then
73 sudo /etc/init.d/elasticsearch stop
74 elif is_fedora; then
75 sudo /bin/systemctl stop elasticsearch.service
76 else
77 echo "Unsupported architecture...can not stop elasticsearch."
78 fi
79}
80
81function install_elasticsearch {
Sean Dague60996b12015-04-08 09:06:49 -040082 pip_install_gr elasticsearch
Sean Daguef8b4f852015-02-04 15:46:03 -050083 if is_package_installed elasticsearch; then
84 echo "Note: elasticsearch was already installed."
85 return
86 fi
87 if is_ubuntu; then
88 is_package_installed openjdk-7-jre-headless || install_package openjdk-7-jre-headless
89
90 sudo dpkg -i ${FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.deb
91 sudo update-rc.d elasticsearch defaults 95 10
92 elif is_fedora; then
Attila Fazekas99b59882015-02-24 12:15:21 +010093 if [[ "$os_RELEASE" -ge "21" ]]; then
94 is_package_installed java-1.8.0-openjdk-headless || install_package java-1.8.0-openjdk-headless
95 else
96 is_package_installed java-1.7.0-openjdk-headless || install_package java-1.7.0-openjdk-headless
97 fi
Sean Daguef8b4f852015-02-04 15:46:03 -050098 yum_install ${FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm
99 sudo /bin/systemctl daemon-reload
100 sudo /bin/systemctl enable elasticsearch.service
101 else
102 echo "Unsupported install of elasticsearch on this architecture."
103 fi
104}
105
106function uninstall_elasticsearch {
107 if is_package_installed elasticsearch; then
108 if is_ubuntu; then
109 sudo apt-get purge elasticsearch
110 elif is_fedora; then
111 sudo yum remove elasticsearch
112 else
113 echo "Unsupported install of elasticsearch on this architecture."
114 fi
115 fi
116}
117
118# The PHASE dispatcher. All pkg files are expected to basically cargo
119# cult the case statement.
120PHASE=$1
121echo "Phase is $PHASE"
122
123case $PHASE in
124 download)
125 download_elasticsearch
126 ;;
127 install)
128 install_elasticsearch
129 ;;
130 configure)
131 configure_elasticsearch
132 ;;
133 start)
134 start_elasticsearch
135 ;;
136 stop)
137 stop_elasticsearch
138 ;;
139 uninstall)
140 uninstall_elasticsearch
141 ;;
142esac