blob: f53c7f2ff2c3488976a825b3f52fc0044491823b [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
10
11# Package source and version, all pkg files are expected to have
12# something like this, as well as a way to override them.
13ELASTICSEARCH_VERSION=${ELASTICSEARCH_VERSION:-1.4.2}
14ELASTICSEARCH_BASEURL=${ELASTICSEARCH_BASEURL:-https://download.elasticsearch.org/elasticsearch/elasticsearch}
15
16# Elastic search actual implementation
17function wget_elasticsearch {
18 local file=${1}
19
20 if [ ! -f ${FILES}/${file} ]; then
21 wget $ELASTICSEARCH_BASEURL/${file} -O ${FILES}/${file}
22 fi
23
24 if [ ! -f ${FILES}/${file}.sha1.txt ]; then
25 wget $ELASTICSEARCH_BASEURL/${file}.sha1.txt -O ${FILES}/${file}.sha1.txt
26 fi
27
28 pushd ${FILES}; sha1sum ${file} > ${file}.sha1.gen; popd
29
30 if ! diff ${FILES}/${file}.sha1.gen ${FILES}/${file}.sha1.txt; then
31 echo "Invalid elasticsearch download. Could not install."
32 return 1
33 fi
34 return 0
35}
36
37function download_elasticsearch {
38 if is_ubuntu; then
39 wget_elasticsearch elasticsearch-${ELASTICSEARCH_VERSION}.deb
40 elif is_fedora; then
41 wget_elasticsearch elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm
42 fi
43}
44
45function configure_elasticsearch {
46 # currently a no op
Attila Fazekas99b59882015-02-24 12:15:21 +010047 :
Sean Daguef8b4f852015-02-04 15:46:03 -050048}
49
gordon chung76e724b2015-02-11 18:28:37 -050050function _check_elasticsearch_ready {
51 # poll elasticsearch to see if it's started
52 if ! wait_for_service 30 http://localhost:9200; then
53 die $LINENO "Maximum timeout reached. Could not connect to ElasticSearch"
54 fi
55}
56
Sean Daguef8b4f852015-02-04 15:46:03 -050057function start_elasticsearch {
58 if is_ubuntu; then
59 sudo /etc/init.d/elasticsearch start
gordon chung76e724b2015-02-11 18:28:37 -050060 _check_elasticsearch_ready
Sean Daguef8b4f852015-02-04 15:46:03 -050061 elif is_fedora; then
62 sudo /bin/systemctl start elasticsearch.service
gordon chung76e724b2015-02-11 18:28:37 -050063 _check_elasticsearch_ready
Sean Daguef8b4f852015-02-04 15:46:03 -050064 else
65 echo "Unsupported architecture...can not start elasticsearch."
66 fi
67}
68
69function stop_elasticsearch {
70 if is_ubuntu; then
71 sudo /etc/init.d/elasticsearch stop
72 elif is_fedora; then
73 sudo /bin/systemctl stop elasticsearch.service
74 else
75 echo "Unsupported architecture...can not stop elasticsearch."
76 fi
77}
78
79function install_elasticsearch {
gordon chung3011ec72015-03-12 00:34:06 -040080 pip_install elasticsearch
Sean Daguef8b4f852015-02-04 15:46:03 -050081 if is_package_installed elasticsearch; then
82 echo "Note: elasticsearch was already installed."
83 return
84 fi
85 if is_ubuntu; then
86 is_package_installed openjdk-7-jre-headless || install_package openjdk-7-jre-headless
87
88 sudo dpkg -i ${FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.deb
89 sudo update-rc.d elasticsearch defaults 95 10
90 elif is_fedora; then
Attila Fazekas99b59882015-02-24 12:15:21 +010091 if [[ "$os_RELEASE" -ge "21" ]]; then
92 is_package_installed java-1.8.0-openjdk-headless || install_package java-1.8.0-openjdk-headless
93 else
94 is_package_installed java-1.7.0-openjdk-headless || install_package java-1.7.0-openjdk-headless
95 fi
Sean Daguef8b4f852015-02-04 15:46:03 -050096 yum_install ${FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm
97 sudo /bin/systemctl daemon-reload
98 sudo /bin/systemctl enable elasticsearch.service
99 else
100 echo "Unsupported install of elasticsearch on this architecture."
101 fi
102}
103
104function uninstall_elasticsearch {
105 if is_package_installed elasticsearch; then
106 if is_ubuntu; then
107 sudo apt-get purge elasticsearch
108 elif is_fedora; then
109 sudo yum remove elasticsearch
110 else
111 echo "Unsupported install of elasticsearch on this architecture."
112 fi
113 fi
114}
115
116# The PHASE dispatcher. All pkg files are expected to basically cargo
117# cult the case statement.
118PHASE=$1
119echo "Phase is $PHASE"
120
121case $PHASE in
122 download)
123 download_elasticsearch
124 ;;
125 install)
126 install_elasticsearch
127 ;;
128 configure)
129 configure_elasticsearch
130 ;;
131 start)
132 start_elasticsearch
133 ;;
134 stop)
135 stop_elasticsearch
136 ;;
137 uninstall)
138 uninstall_elasticsearch
139 ;;
140esac