blob: 447596a8db4d5dbfde511e871c057f66b8c25d4c [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
50function start_elasticsearch {
51 if is_ubuntu; then
52 sudo /etc/init.d/elasticsearch start
53 elif is_fedora; then
54 sudo /bin/systemctl start elasticsearch.service
55 else
56 echo "Unsupported architecture...can not start elasticsearch."
57 fi
58}
59
60function stop_elasticsearch {
61 if is_ubuntu; then
62 sudo /etc/init.d/elasticsearch stop
63 elif is_fedora; then
64 sudo /bin/systemctl stop elasticsearch.service
65 else
66 echo "Unsupported architecture...can not stop elasticsearch."
67 fi
68}
69
70function install_elasticsearch {
71 if is_package_installed elasticsearch; then
72 echo "Note: elasticsearch was already installed."
73 return
74 fi
75 if is_ubuntu; then
76 is_package_installed openjdk-7-jre-headless || install_package openjdk-7-jre-headless
77
78 sudo dpkg -i ${FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.deb
79 sudo update-rc.d elasticsearch defaults 95 10
80 elif is_fedora; then
Attila Fazekas99b59882015-02-24 12:15:21 +010081 if [[ "$os_RELEASE" -ge "21" ]]; then
82 is_package_installed java-1.8.0-openjdk-headless || install_package java-1.8.0-openjdk-headless
83 else
84 is_package_installed java-1.7.0-openjdk-headless || install_package java-1.7.0-openjdk-headless
85 fi
Sean Daguef8b4f852015-02-04 15:46:03 -050086 yum_install ${FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm
87 sudo /bin/systemctl daemon-reload
88 sudo /bin/systemctl enable elasticsearch.service
89 else
90 echo "Unsupported install of elasticsearch on this architecture."
91 fi
92}
93
94function uninstall_elasticsearch {
95 if is_package_installed elasticsearch; then
96 if is_ubuntu; then
97 sudo apt-get purge elasticsearch
98 elif is_fedora; then
99 sudo yum remove elasticsearch
100 else
101 echo "Unsupported install of elasticsearch on this architecture."
102 fi
103 fi
104}
105
106# The PHASE dispatcher. All pkg files are expected to basically cargo
107# cult the case statement.
108PHASE=$1
109echo "Phase is $PHASE"
110
111case $PHASE in
112 download)
113 download_elasticsearch
114 ;;
115 install)
116 install_elasticsearch
117 ;;
118 configure)
119 configure_elasticsearch
120 ;;
121 start)
122 start_elasticsearch
123 ;;
124 stop)
125 stop_elasticsearch
126 ;;
127 uninstall)
128 uninstall_elasticsearch
129 ;;
130esac