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 |
| 9 | source $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. |
| 13 | ELASTICSEARCH_VERSION=${ELASTICSEARCH_VERSION:-1.4.2} |
| 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 |
| 40 | elif is_fedora; then |
| 41 | wget_elasticsearch elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm |
| 42 | fi |
| 43 | } |
| 44 | |
| 45 | function configure_elasticsearch { |
| 46 | # currently a no op |
| 47 | :: |
| 48 | } |
| 49 | |
| 50 | function 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 | |
| 60 | function 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 | |
| 70 | function 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 |
| 81 | is_package_installed java-1.7.0-openjdk-headless || install_package java-1.7.0-openjdk-headless |
| 82 | yum_install ${FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm |
| 83 | sudo /bin/systemctl daemon-reload |
| 84 | sudo /bin/systemctl enable elasticsearch.service |
| 85 | else |
| 86 | echo "Unsupported install of elasticsearch on this architecture." |
| 87 | fi |
| 88 | } |
| 89 | |
| 90 | function uninstall_elasticsearch { |
| 91 | if is_package_installed elasticsearch; then |
| 92 | if is_ubuntu; then |
| 93 | sudo apt-get purge elasticsearch |
| 94 | elif is_fedora; then |
| 95 | sudo yum remove elasticsearch |
| 96 | else |
| 97 | echo "Unsupported install of elasticsearch on this architecture." |
| 98 | fi |
| 99 | fi |
| 100 | } |
| 101 | |
| 102 | # The PHASE dispatcher. All pkg files are expected to basically cargo |
| 103 | # cult the case statement. |
| 104 | PHASE=$1 |
| 105 | echo "Phase is $PHASE" |
| 106 | |
| 107 | case $PHASE in |
| 108 | download) |
| 109 | download_elasticsearch |
| 110 | ;; |
| 111 | install) |
| 112 | install_elasticsearch |
| 113 | ;; |
| 114 | configure) |
| 115 | configure_elasticsearch |
| 116 | ;; |
| 117 | start) |
| 118 | start_elasticsearch |
| 119 | ;; |
| 120 | stop) |
| 121 | stop_elasticsearch |
| 122 | ;; |
| 123 | uninstall) |
| 124 | uninstall_elasticsearch |
| 125 | ;; |
| 126 | esac |