the first implementation of arbitrary installation in tree for
components for elasticsearch.
Change-Id: I88e852ad009735ae77c6d4c19c4f4838c49cc0ad
1 | 1 |
new file mode 100755 |
... | ... |
@@ -0,0 +1,126 @@ |
0 |
+#!/bin/bash -xe |
|
1 |
+ |
|
2 |
+# basic reference point for things like filecache |
|
3 |
+# |
|
4 |
+# TODO(sdague): once we have a few of these I imagine the download |
|
5 |
+# step can probably be factored out to something nicer |
|
6 |
+TOP_DIR=$(cd $(dirname "$0")/.. && pwd) |
|
7 |
+FILES=$TOP_DIR/files |
|
8 |
+source $TOP_DIR/functions |
|
9 |
+ |
|
10 |
+# Package source and version, all pkg files are expected to have |
|
11 |
+# something like this, as well as a way to override them. |
|
12 |
+ELASTICSEARCH_VERSION=${ELASTICSEARCH_VERSION:-1.4.2} |
|
13 |
+ELASTICSEARCH_BASEURL=${ELASTICSEARCH_BASEURL:-https://download.elasticsearch.org/elasticsearch/elasticsearch} |
|
14 |
+ |
|
15 |
+# Elastic search actual implementation |
|
16 |
+function wget_elasticsearch { |
|
17 |
+ local file=${1} |
|
18 |
+ |
|
19 |
+ if [ ! -f ${FILES}/${file} ]; then |
|
20 |
+ wget $ELASTICSEARCH_BASEURL/${file} -O ${FILES}/${file} |
|
21 |
+ fi |
|
22 |
+ |
|
23 |
+ if [ ! -f ${FILES}/${file}.sha1.txt ]; then |
|
24 |
+ wget $ELASTICSEARCH_BASEURL/${file}.sha1.txt -O ${FILES}/${file}.sha1.txt |
|
25 |
+ fi |
|
26 |
+ |
|
27 |
+ pushd ${FILES}; sha1sum ${file} > ${file}.sha1.gen; popd |
|
28 |
+ |
|
29 |
+ if ! diff ${FILES}/${file}.sha1.gen ${FILES}/${file}.sha1.txt; then |
|
30 |
+ echo "Invalid elasticsearch download. Could not install." |
|
31 |
+ return 1 |
|
32 |
+ fi |
|
33 |
+ return 0 |
|
34 |
+} |
|
35 |
+ |
|
36 |
+function download_elasticsearch { |
|
37 |
+ if is_ubuntu; then |
|
38 |
+ wget_elasticsearch elasticsearch-${ELASTICSEARCH_VERSION}.deb |
|
39 |
+ elif is_fedora; then |
|
40 |
+ wget_elasticsearch elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm |
|
41 |
+ fi |
|
42 |
+} |
|
43 |
+ |
|
44 |
+function configure_elasticsearch { |
|
45 |
+ # currently a no op |
|
46 |
+ :: |
|
47 |
+} |
|
48 |
+ |
|
49 |
+function start_elasticsearch { |
|
50 |
+ if is_ubuntu; then |
|
51 |
+ sudo /etc/init.d/elasticsearch start |
|
52 |
+ elif is_fedora; then |
|
53 |
+ sudo /bin/systemctl start elasticsearch.service |
|
54 |
+ else |
|
55 |
+ echo "Unsupported architecture...can not start elasticsearch." |
|
56 |
+ fi |
|
57 |
+} |
|
58 |
+ |
|
59 |
+function stop_elasticsearch { |
|
60 |
+ if is_ubuntu; then |
|
61 |
+ sudo /etc/init.d/elasticsearch stop |
|
62 |
+ elif is_fedora; then |
|
63 |
+ sudo /bin/systemctl stop elasticsearch.service |
|
64 |
+ else |
|
65 |
+ echo "Unsupported architecture...can not stop elasticsearch." |
|
66 |
+ fi |
|
67 |
+} |
|
68 |
+ |
|
69 |
+function install_elasticsearch { |
|
70 |
+ if is_package_installed elasticsearch; then |
|
71 |
+ echo "Note: elasticsearch was already installed." |
|
72 |
+ return |
|
73 |
+ fi |
|
74 |
+ if is_ubuntu; then |
|
75 |
+ is_package_installed openjdk-7-jre-headless || install_package openjdk-7-jre-headless |
|
76 |
+ |
|
77 |
+ sudo dpkg -i ${FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.deb |
|
78 |
+ sudo update-rc.d elasticsearch defaults 95 10 |
|
79 |
+ elif is_fedora; then |
|
80 |
+ is_package_installed java-1.7.0-openjdk-headless || install_package java-1.7.0-openjdk-headless |
|
81 |
+ yum_install ${FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm |
|
82 |
+ sudo /bin/systemctl daemon-reload |
|
83 |
+ sudo /bin/systemctl enable elasticsearch.service |
|
84 |
+ else |
|
85 |
+ echo "Unsupported install of elasticsearch on this architecture." |
|
86 |
+ fi |
|
87 |
+} |
|
88 |
+ |
|
89 |
+function uninstall_elasticsearch { |
|
90 |
+ if is_package_installed elasticsearch; then |
|
91 |
+ if is_ubuntu; then |
|
92 |
+ sudo apt-get purge elasticsearch |
|
93 |
+ elif is_fedora; then |
|
94 |
+ sudo yum remove elasticsearch |
|
95 |
+ else |
|
96 |
+ echo "Unsupported install of elasticsearch on this architecture." |
|
97 |
+ fi |
|
98 |
+ fi |
|
99 |
+} |
|
100 |
+ |
|
101 |
+# The PHASE dispatcher. All pkg files are expected to basically cargo |
|
102 |
+# cult the case statement. |
|
103 |
+PHASE=$1 |
|
104 |
+echo "Phase is $PHASE" |
|
105 |
+ |
|
106 |
+case $PHASE in |
|
107 |
+ download) |
|
108 |
+ download_elasticsearch |
|
109 |
+ ;; |
|
110 |
+ install) |
|
111 |
+ install_elasticsearch |
|
112 |
+ ;; |
|
113 |
+ configure) |
|
114 |
+ configure_elasticsearch |
|
115 |
+ ;; |
|
116 |
+ start) |
|
117 |
+ start_elasticsearch |
|
118 |
+ ;; |
|
119 |
+ stop) |
|
120 |
+ stop_elasticsearch |
|
121 |
+ ;; |
|
122 |
+ uninstall) |
|
123 |
+ uninstall_elasticsearch |
|
124 |
+ ;; |
|
125 |
+esac |