Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 1 | #!/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 |
| 7 | TOP_DIR=$(cd $(dirname "$0")/.. && pwd) |
| 8 | FILES=$TOP_DIR/files |
gordon chung | b203d0c | 2015-08-12 11:58:11 -0400 | [diff] [blame] | 9 | source $TOP_DIR/stackrc |
Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 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. |
Travis Tripp | b523f31 | 2016-05-05 10:19:53 -0600 | [diff] [blame] | 13 | ELASTICSEARCH_VERSION=${ELASTICSEARCH_VERSION:-1.7.5} |
Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 14 | ELASTICSEARCH_BASEURL=${ELASTICSEARCH_BASEURL:-https://download.elasticsearch.org/elasticsearch/elasticsearch} |
| 15 | |
| 16 | # Elastic search actual implementation |
| 17 | function 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 | |
| 37 | function download_elasticsearch { |
| 38 | if is_ubuntu; then |
| 39 | wget_elasticsearch elasticsearch-${ELASTICSEARCH_VERSION}.deb |
Sumit Jamgade | 53e9aca | 2018-06-13 17:30:41 +0200 | [diff] [blame] | 40 | elif is_fedora || is_suse; then |
Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 41 | wget_elasticsearch elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm |
| 42 | fi |
| 43 | } |
| 44 | |
| 45 | function configure_elasticsearch { |
| 46 | # currently a no op |
Attila Fazekas | 99b5988 | 2015-02-24 12:15:21 +0100 | [diff] [blame] | 47 | : |
Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 48 | } |
| 49 | |
gordon chung | 76e724b | 2015-02-11 18:28:37 -0500 | [diff] [blame] | 50 | function _check_elasticsearch_ready { |
| 51 | # poll elasticsearch to see if it's started |
Sylvain Afchain | 19eefe5 | 2018-07-04 17:59:34 +0200 | [diff] [blame] | 52 | if ! wait_for_service 120 http://localhost:9200; then |
gordon chung | 76e724b | 2015-02-11 18:28:37 -0500 | [diff] [blame] | 53 | die $LINENO "Maximum timeout reached. Could not connect to ElasticSearch" |
| 54 | fi |
| 55 | } |
| 56 | |
Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 57 | function start_elasticsearch { |
| 58 | if is_ubuntu; then |
| 59 | sudo /etc/init.d/elasticsearch start |
gordon chung | 76e724b | 2015-02-11 18:28:37 -0500 | [diff] [blame] | 60 | _check_elasticsearch_ready |
Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 61 | elif is_fedora; then |
| 62 | sudo /bin/systemctl start elasticsearch.service |
gordon chung | 76e724b | 2015-02-11 18:28:37 -0500 | [diff] [blame] | 63 | _check_elasticsearch_ready |
Sumit Jamgade | 53e9aca | 2018-06-13 17:30:41 +0200 | [diff] [blame] | 64 | elif is_suse; then |
| 65 | sudo /usr/bin/systemctl start elasticsearch.service |
| 66 | _check_elasticsearch_ready |
Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 67 | else |
| 68 | echo "Unsupported architecture...can not start elasticsearch." |
| 69 | fi |
| 70 | } |
| 71 | |
| 72 | function stop_elasticsearch { |
| 73 | if is_ubuntu; then |
| 74 | sudo /etc/init.d/elasticsearch stop |
| 75 | elif is_fedora; then |
| 76 | sudo /bin/systemctl stop elasticsearch.service |
Sumit Jamgade | 53e9aca | 2018-06-13 17:30:41 +0200 | [diff] [blame] | 77 | elif is_suse ; then |
| 78 | sudo /usr/bin/systemctl stop elasticsearch.service |
Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 79 | else |
| 80 | echo "Unsupported architecture...can not stop elasticsearch." |
| 81 | fi |
| 82 | } |
| 83 | |
| 84 | function install_elasticsearch { |
Sean Dague | 60996b1 | 2015-04-08 09:06:49 -0400 | [diff] [blame] | 85 | pip_install_gr elasticsearch |
Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 86 | if is_package_installed elasticsearch; then |
| 87 | echo "Note: elasticsearch was already installed." |
| 88 | return |
| 89 | fi |
| 90 | if is_ubuntu; then |
Clark Boylan | a09cb5a | 2016-12-14 07:57:26 -0800 | [diff] [blame] | 91 | is_package_installed default-jre-headless || install_package default-jre-headless |
Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 92 | |
| 93 | sudo dpkg -i ${FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.deb |
| 94 | sudo update-rc.d elasticsearch defaults 95 10 |
| 95 | elif is_fedora; then |
Federico Ressi | 3809def | 2016-01-06 08:19:24 +0000 | [diff] [blame] | 96 | is_package_installed java-1.8.0-openjdk-headless || install_package java-1.8.0-openjdk-headless |
Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 97 | yum_install ${FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm |
| 98 | sudo /bin/systemctl daemon-reload |
| 99 | sudo /bin/systemctl enable elasticsearch.service |
Sumit Jamgade | 53e9aca | 2018-06-13 17:30:41 +0200 | [diff] [blame] | 100 | elif is_suse; then |
| 101 | is_package_installed java-1_8_0-openjdk-headless || install_package java-1_8_0-openjdk-headless |
| 102 | zypper_install --no-gpg-checks ${FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm |
| 103 | sudo /usr/bin/systemctl daemon-reload |
| 104 | sudo /usr/bin/systemctl enable elasticsearch.service |
Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 105 | else |
| 106 | echo "Unsupported install of elasticsearch on this architecture." |
| 107 | fi |
| 108 | } |
| 109 | |
| 110 | function uninstall_elasticsearch { |
| 111 | if is_package_installed elasticsearch; then |
| 112 | if is_ubuntu; then |
| 113 | sudo apt-get purge elasticsearch |
| 114 | elif is_fedora; then |
| 115 | sudo yum remove elasticsearch |
Sumit Jamgade | 53e9aca | 2018-06-13 17:30:41 +0200 | [diff] [blame] | 116 | elif is_suse; then |
| 117 | sudo zypper rm elasticsearch |
Sean Dague | f8b4f85 | 2015-02-04 15:46:03 -0500 | [diff] [blame] | 118 | else |
| 119 | echo "Unsupported install of elasticsearch on this architecture." |
| 120 | fi |
| 121 | fi |
| 122 | } |
| 123 | |
| 124 | # The PHASE dispatcher. All pkg files are expected to basically cargo |
| 125 | # cult the case statement. |
| 126 | PHASE=$1 |
| 127 | echo "Phase is $PHASE" |
| 128 | |
| 129 | case $PHASE in |
| 130 | download) |
| 131 | download_elasticsearch |
| 132 | ;; |
| 133 | install) |
| 134 | install_elasticsearch |
| 135 | ;; |
| 136 | configure) |
| 137 | configure_elasticsearch |
| 138 | ;; |
| 139 | start) |
| 140 | start_elasticsearch |
| 141 | ;; |
| 142 | stop) |
| 143 | stop_elasticsearch |
| 144 | ;; |
| 145 | uninstall) |
| 146 | uninstall_elasticsearch |
| 147 | ;; |
| 148 | esac |