"Fossies" - the Fresh Open Source Software Archive

Member "monasca-api-3.1.0/devstack/lib/storm.sh" (27 Sep 2019, 5004 Bytes) of package /linux/misc/openstack/monasca-api-3.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/bash
    2 
    3 # Copyright 2017 FUJITSU LIMITED
    4 #
    5 # Licensed under the Apache License, Version 2.0 (the "License"); you may
    6 # not use this file except in compliance with the License. You may obtain
    7 # a copy of the License at
    8 #
    9 #      http://www.apache.org/licenses/LICENSE-2.0
   10 #
   11 # Unless required by applicable law or agreed to in writing, software
   12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   14 # License for the specific language governing permissions and limitations
   15 # under the License.
   16 
   17 # call_order:
   18 # - is_storm_enabled
   19 # - install_storm
   20 # - configure_storm
   21 # - clean_storm
   22 
   23 _XTRACE_STORM=$(set +o | grep xtrace)
   24 set +o xtrace
   25 
   26 STORM_USER="storm"
   27 STORM_GROUP="storm"
   28 
   29 STORM_DIR="/opt/storm"
   30 STORM_CURRENT_DIR="${STORM_DIR}/current"
   31 STORM_BIN="${STORM_CURRENT_DIR}/bin/storm"
   32 STORM_WORK_DIR="/var/storm"
   33 STORM_LOG_DIR="/var/log/storm"
   34 
   35 STORM_TARBALL="apache-storm-${STORM_VERSION}.tar.gz"
   36 STORM_TARBALL_DEST="${FILES}/${STORM_TARBALL}"
   37 
   38 STORM_NIMBUS_CMD="${STORM_BIN} nimbus"
   39 STORM_SUPERVISOR_CMD="${STORM_BIN} supervisor"
   40 STORM_UI_CMD="${STORM_BIN} ui"
   41 STORM_LOGVIEWER_CMD="${STORM_BIN} logviewer"
   42 
   43 function is_storm_enabled {
   44     [[ ,${ENABLED_SERVICES} =~ ,"monasca-storm" ]] && return 0
   45     return 1
   46 }
   47 
   48 function start_storm {
   49     if is_storm_enabled; then
   50         echo_summary "Starting storm"
   51 
   52         run_process "monasca-storm-nimbus" "${STORM_NIMBUS_CMD}" "${STORM_GROUP}" "${STORM_USER}"
   53         run_process "monasca-storm-supervisor" "${STORM_SUPERVISOR_CMD}" "${STORM_GROUP}" "${STORM_USER}"
   54         run_process "monasca-storm-ui" "${STORM_UI_CMD}" "${STORM_GROUP}" "${STORM_USER}"
   55         run_process "monasca-storm-logviewer" "${STORM_LOGVIEWER_CMD}" "${STORM_GROUP}" "${STORM_USER}"
   56     fi
   57 }
   58 
   59 function stop_storm {
   60     if is_storm_enabled; then
   61         echo_summary "Stopping storm"
   62 
   63         stop_process "monasca-storm-nimbus"
   64         stop_process "monasca-storm-supervisor"
   65         stop_process "monasca-storm-ui"
   66         stop_process "monasca-storm-logviewer"
   67     fi
   68 }
   69 
   70 function clean_storm {
   71     if is_storm_enabled; then
   72         echo_summary "Cleaning storm"
   73 
   74         sudo unlink "${DEST}/logs/storm-workers" || true
   75         sudo unlink "${STORM_CURRENT_DIR}/logs"|| true
   76         sudo unlink "${STORM_CURRENT_DIR}"|| true
   77 
   78         sudo rm -rf "${DEST}/logs/storm-workers" || true
   79         sudo rm -rf "${STORM_CURRENT_DIR}"|| true
   80         sudo rm -rf "${STORM_DIR}" || true
   81         sudo rm -rf "${STORM_WORK_DIR}" || true
   82         sudo rm -rf "${STORM_LOG_DIR}" || true
   83 
   84         sudo userdel "${STORM_USER}" || true
   85         sudo groupdel "${STORM_GROUP}" || true
   86     fi
   87 }
   88 
   89 function configure_storm {
   90     if is_storm_enabled; then
   91         echo_summary "Configuring storm"
   92         sudo cp -f "${MONASCA_API_DIR}"/devstack/files/storm.yaml "${STORM_CURRENT_DIR}/conf/storm.yaml"
   93         sudo chown "${STORM_USER}":"${STORM_GROUP}" "${STORM_CURRENT_DIR}/conf/storm.yaml"
   94         sudo chmod 0644 "${STORM_CURRENT_DIR}/conf/storm.yaml"
   95 
   96         sudo sed -e "
   97             s|%STORM_UI_HOST%|${STORM_UI_HOST}|g;
   98             s|%STORM_UI_PORT%|${STORM_UI_PORT}|g;
   99             s|%STORM_LOGVIEWER_PORT%|${STORM_LOGVIEWER_PORT}|g;
  100         " -i "${STORM_CURRENT_DIR}/conf/storm.yaml"
  101 
  102     fi
  103 }
  104 
  105 function install_storm {
  106     if is_storm_enabled; then
  107         echo_summary "Installing storm"
  108         _download_storm
  109         _setup_user_group
  110         _create_directories
  111         _install_storm
  112     fi
  113 }
  114 
  115 function post_storm {
  116     if is_storm_enabled; then
  117         echo "Post configuring storm"
  118         # if inside the gate, make the visible there too
  119         if [ -n "${LOGDIR}" ]; then
  120             sudo ln -sfd "${STORM_LOG_DIR}/workers-artifacts" "${LOGDIR}/storm-workers"
  121         fi
  122     fi
  123 }
  124 
  125 # helpers
  126 
  127 function _download_storm {
  128     local storm_tarball_url="${APACHE_ARCHIVES}storm/apache-storm-${STORM_VERSION}/${STORM_TARBALL}"
  129     local storm_dest
  130 
  131     storm_dest=`get_extra_file ${storm_tarball_url}`
  132 
  133     if [ "${storm_dest}" != "${STORM_TARBALL_DEST}" ]; then
  134         mv -f "${storm_dest}" "${STORM_TARBALL_DEST}"
  135     fi
  136 }
  137 
  138 function _setup_user_group {
  139     sudo groupadd --system "${STORM_GROUP}" || true
  140     sudo useradd --system -g "${STORM_GROUP}" "${STORM_USER}" || true
  141 }
  142 
  143 function _install_storm {
  144     # unpack (i.e. install) downloaded tarball
  145     sudo tar -xzf ${STORM_TARBALL_DEST} -C "${STORM_DIR}"
  146 
  147     # link the versioned folder to more suitable one
  148     sudo ln -sfd "${STORM_DIR}/apache-storm-${STORM_VERSION}" "${STORM_CURRENT_DIR}"
  149 
  150     # make them visible in standard location
  151     sudo ln -sfd "${STORM_LOG_DIR}" "${STORM_CURRENT_DIR}/logs"
  152 }
  153 
  154 function _create_directories {
  155     for dir in "${STORM_DIR}" "${STORM_WORK_DIR}" "${STORM_LOG_DIR}"; do
  156         if [ ! -d "${dir}" ]; then
  157             sudo mkdir -p "${dir}" || true
  158         fi
  159         sudo chown "${STORM_USER}":"${STORM_GROUP}" "${dir}"
  160         sudo chmod 0775 "${dir}"
  161     done
  162 }
  163 
  164 # helpers
  165 
  166 $_XTRACE_STORM