File: elasticsearch.sh

package info (click to toggle)
freezer-api 9.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,884 kB
  • sloc: python: 15,677; sh: 388; makefile: 56
file content (149 lines) | stat: -rwxr-xr-x 4,761 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash -xe

# basic reference point for things like filecache
#
# TODO(sdague): once we have a few of these I imagine the download
# step can probably be factored out to something nicer

# Package source and version, all pkg files are expected to have
# something like this, as well as a way to override them.
ELASTICSEARCH_VERSION=${ELASTICSEARCH_VERSION:-1.7.5}
ELASTICSEARCH_BASEURL=${ELASTICSEARCH_BASEURL:-https://download.elasticsearch.org/elasticsearch/elasticsearch}

# Elastic search actual implementation
function wget_elasticsearch {
    local file=${1}

    if [ ! -f ${FREEZER_API_FILES}/${file} ]; then
        wget $ELASTICSEARCH_BASEURL/${file} -O ${FREEZER_API_FILES}/${file}
    fi

    if [ ! -f ${FREEZER_API_FILES}/${file}.sha1.txt ]; then
        wget $ELASTICSEARCH_BASEURL/${file}.sha1.txt -O ${FREEZER_API_FILES}/${file}.sha1.txt
    fi

    pushd ${FREEZER_API_FILES};  sha1sum ${file} > ${file}.sha1.gen;  popd

    if ! diff ${FREEZER_API_FILES}/${file}.sha1.gen ${FREEZER_API_FILES}/${file}.sha1.txt; then
        echo "Invalid elasticsearch download. Could not install."
        return 1
    fi
    return 0
}

function download_elasticsearch {
    if is_ubuntu; then
        wget_elasticsearch elasticsearch-${ELASTICSEARCH_VERSION}.deb
    elif is_fedora || is_suse; then
        wget_elasticsearch elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm
    fi
}

function configure_elasticsearch {
    # currently a no op
    :
}

function _check_elasticsearch_ready {
    # poll elasticsearch to see if it's started
    if ! wait_for_service 120 http://localhost:9200; then
        die $LINENO "Maximum timeout reached. Could not connect to ElasticSearch"
    fi
}

function start_elasticsearch {
    if is_ubuntu; then
        sudo /etc/init.d/elasticsearch start
        _check_elasticsearch_ready
    elif is_fedora; then
        sudo /bin/systemctl start elasticsearch.service
        _check_elasticsearch_ready
    elif is_suse; then
        sudo /usr/bin/systemctl start elasticsearch.service
        _check_elasticsearch_ready
    else
        echo "Unsupported architecture...can not start elasticsearch."
    fi
}

function stop_elasticsearch {
    if is_ubuntu; then
        sudo /etc/init.d/elasticsearch stop
    elif is_fedora; then
        sudo /bin/systemctl stop elasticsearch.service
    elif is_suse ; then
        sudo /usr/bin/systemctl stop elasticsearch.service
    else
        echo "Unsupported architecture...can not stop elasticsearch."
    fi
}

function install_elasticsearch {
    pip_install_gr elasticsearch
    if is_package_installed elasticsearch; then
        echo "Note: elasticsearch was already installed."
        return
    fi
    if is_ubuntu; then
        if [[ ${DISTRO} == "bionic" ]]; then
            is_package_installed openjdk-8-jre-headless || install_package openjdk-8-jre-headless
        else
            is_package_installed default-jre-headless || install_package default-jre-headless
        fi

        sudo dpkg -i ${FREEZER_API_FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.deb
        sudo update-rc.d elasticsearch defaults 95 10
    elif is_fedora; then
        is_package_installed java-1.8.0-openjdk-headless || install_package java-1.8.0-openjdk-headless
        yum_install ${FREEZER_API_FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm
        sudo /bin/systemctl daemon-reload
        sudo /bin/systemctl enable elasticsearch.service
    elif is_suse; then
        is_package_installed java-1_8_0-openjdk-headless || install_package java-1_8_0-openjdk-headless
        zypper_install --no-gpg-checks ${FREEZER_API_FILES}/elasticsearch-${ELASTICSEARCH_VERSION}.noarch.rpm
        sudo /usr/bin/systemctl daemon-reload
        sudo /usr/bin/systemctl enable elasticsearch.service
    else
        echo "Unsupported install of elasticsearch on this architecture."
    fi
}

function uninstall_elasticsearch {
    if is_package_installed elasticsearch; then
        if is_ubuntu; then
            sudo apt-get purge elasticsearch
        elif is_fedora; then
            sudo yum remove elasticsearch
        elif is_suse; then
            sudo zypper rm elasticsearch
        else
            echo "Unsupported install of elasticsearch on this architecture."
        fi
    fi
}

# The PHASE dispatcher. All pkg files are expected to basically cargo
# cult the case statement.
PHASE=$1
echo "Phase is $PHASE"

case $PHASE in
    download)
        download_elasticsearch
        ;;
    install)
        install_elasticsearch
        ;;
    configure)
        configure_elasticsearch
        ;;
    start)
        start_elasticsearch
        ;;
    stop)
        stop_elasticsearch
        ;;
    uninstall)
        uninstall_elasticsearch
        ;;
esac