"Fossies" - the Fresh Open Source Software Archive

Member "monasca-log-api-2.9.0/devstack/plugin.sh" (1 Apr 2019, 29744 Bytes) of package /linux/misc/openstack/monasca-log-api-2.9.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. See also the latest Fossies "Diffs" side-by-side code changes report for "plugin.sh": 2.7.0_vs_2.9.0.

    1 #!/bin/bash
    2 
    3 #
    4 # Copyright 2016-2017 FUJITSU LIMITED
    5 #
    6 # Licensed under the Apache License, Version 2.0 (the "License");
    7 # you may not use this file except in compliance with the License.
    8 # You may obtain a copy of the License at
    9 #
   10 #    http://www.apache.org/licenses/LICENSE-2.0
   11 #
   12 # Unless required by applicable law or agreed to in writing, software
   13 # distributed under the License is distributed on an "AS IS" BASIS,
   14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
   15 # implied.
   16 # See the License for the specific language governing permissions and
   17 # limitations under the License.
   18 #
   19 
   20 # Save trace setting
   21 _XTRACE_LOG_API=$(set +o | grep xtrace)
   22 set -o xtrace
   23 
   24 _ERREXIT_LOG_API=$(set +o | grep errexit)
   25 set -o errexit
   26 
   27 # source lib/*
   28 source ${MONASCA_LOG_API_DIR}/devstack/lib/util.sh
   29 source ${MONASCA_LOG_API_DIR}/devstack/lib/config.sh
   30 # source lib/*
   31 
   32 # TOP_LEVEL functions called from devstack coordinator
   33 ###############################################################################
   34 function pre_install {
   35     install_elk
   36     install_nodejs
   37     install_gate_config_holder
   38 }
   39 
   40 function install_monasca_log {
   41     build_kibana_plugin
   42     if is_service_enabled monasca-log-api; then
   43         # install_monasca-log-api is not called directly
   44         # stack_install_service calls it
   45         if python3_enabled; then
   46             enable_python3_package monasca-log-api
   47         fi
   48         stack_install_service monasca-log-api
   49     fi
   50     install_log_agent
   51 }
   52 
   53 function install_elk {
   54     install_logstash
   55     install_elasticsearch
   56     install_kibana
   57 }
   58 
   59 function install_gate_config_holder {
   60     sudo install -d -o $STACK_USER $GATE_CONFIGURATION_DIR
   61 }
   62 
   63 function install_monasca_common {
   64     if use_library_from_git "monasca-common"; then
   65         git_clone_by_name "monasca-common"
   66         setup_dev_lib "monasca-common"
   67     fi
   68 }
   69 
   70 function install_monasca_statsd {
   71     if use_library_from_git "monasca-statsd"; then
   72         git_clone_by_name "monasca-statsd"
   73         setup_dev_lib "monasca-statsd"
   74     fi
   75 }
   76 
   77 function configure_monasca_log {
   78     configure_kafka
   79     configure_elasticsearch
   80     configure_kibana
   81     install_kibana_plugin
   82 
   83     configure_monasca_log_api
   84     configure_monasca_log_transformer
   85     configure_monasca_log_metrics
   86     configure_monasca_log_persister
   87     configure_monasca_log_agent
   88 }
   89 
   90 function init_monasca_log {
   91     enable_log_management
   92     create_log_management_accounts
   93 }
   94 
   95 function init_monasca_grafana_dashboards {
   96     if is_service_enabled horizon; then
   97         echo_summary "Init Grafana dashboards"
   98 
   99         sudo python "${PLUGIN_FILES}"/grafana/grafana.py "${PLUGIN_FILES}"/grafana/dashboards.d
  100     fi
  101 }
  102 
  103 function init_agent {
  104     echo_summary "Init Monasca agent"
  105 
  106     sudo cp -f "${PLUGIN_FILES}"/monasca-agent/http_check.yaml /etc/monasca/agent/conf.d/http_check.yaml
  107     sudo cp -f "${PLUGIN_FILES}"/monasca-agent/process.yaml /etc/monasca/agent/conf.d/process.yaml
  108     sudo cp -f "${PLUGIN_FILES}"/monasca-agent/elastic.yaml /etc/monasca/agent/conf.d/elastic.yaml
  109 
  110     sudo sed -i "s/{{IP}}/$(ip -o -4 addr list eth1 | awk '{print $4}' | cut -d/ -f1 | head -1)/" /etc/monasca/agent/conf.d/*.yaml
  111     sudo sed -i "s/127\.0\.0\.1/$(hostname)/" /etc/monasca/agent/conf.d/*.yaml
  112     sudo systemctl restart monasca-collector
  113 }
  114 
  115 function stop_monasca_log {
  116     stop_process "monasca-log-agent" || true
  117     stop_monasca_log_api
  118     stop_process "monasca-log-metrics" || true
  119     stop_process "monasca-log-persister" || true
  120     stop_process "monasca-log-transformer" || true
  121     stop_process "kibana" || true
  122     stop_process "elasticsearch" || true
  123 }
  124 
  125 function start_monasca_log {
  126     start_elasticsearch
  127     start_kibana
  128     start_monasca_log_transformer
  129     start_monasca_log_metrics
  130     start_monasca_log_persister
  131     start_monasca_log_api
  132     start_monasca_log_agent
  133 }
  134 
  135 function clean_monasca_log {
  136     clean_monasca_log_agent
  137     clean_monasca_log_api
  138     clean_monasca_log_persister
  139     clean_monasca_log_transformer
  140     clean_kibana
  141     clean_elasticsearch
  142     clean_logstash
  143     clean_nodejs
  144     clean_gate_config_holder
  145 }
  146 ###############################################################################
  147 
  148 function install_monasca-log-api {
  149     echo_summary "Installing monasca-log-api"
  150 
  151     git_clone $MONASCA_LOG_API_REPO $MONASCA_LOG_API_DIR $MONASCA_LOG_API_BRANCH
  152     setup_develop $MONASCA_LOG_API_DIR
  153 
  154     install_keystonemiddleware
  155     install_monasca_common
  156     install_monasca_statsd
  157 
  158     if [ "$MONASCA_LOG_API_DEPLOY" == "mod_wsgi" ]; then
  159         install_apache_wsgi
  160     elif [ "$MONASCA_LOG_API_DEPLOY" == "uwsgi" ]; then
  161         pip_install uwsgi
  162     else
  163         pip_install gunicorn
  164     fi
  165 
  166     if [ "$MONASCA_LOG_API_DEPLOY" != "gunicorn" ]; then
  167         if is_ssl_enabled_service "monasca-log-api"; then
  168             enable_mod_ssl
  169         fi
  170     fi
  171 }
  172 
  173 function configure_monasca_log_api {
  174     if is_service_enabled monasca-log-api; then
  175         echo_summary "Configuring monasca-log-api"
  176 
  177         configure_monasca_log_api_core
  178         if [ "$MONASCA_LOG_API_DEPLOY" == "mod_wsgi" ]; then
  179             configure_monasca_log_api_mod_wsgi
  180         elif [ "$MONASCA_LOG_API_DEPLOY" == "uwsgi" ]; then
  181             configure_monasca_log_api_uwsgi
  182         fi
  183 
  184         # link configuration for the gate
  185         ln -sf $MONASCA_LOG_API_CONF $GATE_CONFIGURATION_DIR
  186         ln -sf $MONASCA_LOG_API_PASTE $GATE_CONFIGURATION_DIR
  187         ln -sf $MONASCA_LOG_API_LOGGING_CONF $GATE_CONFIGURATION_DIR
  188 
  189     fi
  190 }
  191 
  192 function configure_monasca_log_api_core {
  193     # Put config files in ``$MONASCA_LOG_API_CONF_DIR`` for everyone to find
  194     sudo install -d -o $STACK_USER $MONASCA_LOG_API_CONF_DIR
  195     sudo install -m 700 -d -o $STACK_USER $MONASCA_LOG_API_CACHE_DIR
  196     sudo install -d -o $STACK_USER $MONASCA_LOG_API_LOG_DIR
  197 
  198     # ensure fresh installation of configuration files
  199     rm -rf $MONASCA_LOG_API_CONF $MONASCA_LOG_API_PASTE $MONASCA_LOG_API_LOGGING_CONF
  200 
  201     $MONASCA_LOG_API_BIN_DIR/oslo-config-generator \
  202         --config-file $MONASCA_LOG_API_DIR/config-generator/monasca-log-api.conf \
  203         --output-file /tmp/monasca-log-api.conf
  204 
  205     install -m 600 /tmp/monasca-log-api.conf $MONASCA_LOG_API_CONF && rm -rf /tmp/monasca-log-api.conf
  206     install -m 600 $MONASCA_LOG_API_DIR/etc/monasca/log-api-paste.ini $MONASCA_LOG_API_PASTE
  207     install -m 600 $MONASCA_LOG_API_DIR/etc/monasca/log-api-logging.conf $MONASCA_LOG_API_LOGGING_CONF
  208 
  209     # configure monasca-log-api.conf
  210     iniset "$MONASCA_LOG_API_CONF" DEFAULT log_config_append $MONASCA_LOG_API_LOGGING_CONF
  211     iniset "$MONASCA_LOG_API_CONF" service region $REGION_NAME
  212 
  213     iniset "$MONASCA_LOG_API_CONF" log_publisher kafka_url $KAFKA_SERVICE_HOST:$KAFKA_SERVICE_PORT
  214     iniset "$MONASCA_LOG_API_CONF" log_publisher topics log
  215 
  216     iniset "$MONASCA_LOG_API_CONF" kafka_healthcheck kafka_url $KAFKA_SERVICE_HOST:$KAFKA_SERVICE_PORT
  217     iniset "$MONASCA_LOG_API_CONF" kafka_healthcheck kafka_topics log
  218 
  219     iniset "$MONASCA_LOG_API_CONF" roles_middleware path "/v2.0/log,/v3.0/logs"
  220     iniset "$MONASCA_LOG_API_CONF" roles_middleware default_roles monasca-user
  221     iniset "$MONASCA_LOG_API_CONF" roles_middleware agent_roles monasca-agent
  222     iniset "$MONASCA_LOG_API_CONF" roles_middleware delegate_roles admin
  223 
  224     # configure keystone middleware
  225     configure_auth_token_middleware "$MONASCA_LOG_API_CONF" "admin" $MONASCA_LOG_API_CACHE_DIR
  226     iniset "$MONASCA_LOG_API_CONF" keystone_authtoken region_name $REGION_NAME
  227     iniset "$MONASCA_LOG_API_CONF" keystone_authtoken project_name "admin"
  228     iniset "$MONASCA_LOG_API_CONF" keystone_authtoken password $ADMIN_PASSWORD
  229 
  230     # insecure
  231     if is_service_enabled tls-proxy; then
  232         iniset "$MONASCA_LOG_API_CONF" keystone_authtoken insecure False
  233     fi
  234 
  235     # configure log-api-paste.ini
  236     iniset "$MONASCA_LOG_API_PASTE" server:main bind $MONASCA_LOG_API_SERVICE_HOST:$MONASCA_LOG_API_SERVICE_PORT
  237     iniset "$MONASCA_LOG_API_PASTE" server:main chdir $MONASCA_LOG_API_DIR
  238     iniset "$MONASCA_LOG_API_PASTE" server:main workers $API_WORKERS
  239 }
  240 
  241 function configure_monasca_log_api_uwsgi {
  242     rm -rf $MONASCA_LOG_API_UWSGI_CONF
  243     install -m 600 $MONASCA_LOG_API_DIR/etc/monasca/log-api-uwsgi.ini $MONASCA_LOG_API_UWSGI_CONF
  244 
  245     write_uwsgi_config "$MONASCA_LOG_API_UWSGI_CONF" "$MONASCA_LOG_API_WSGI" "/logs"
  246 }
  247 
  248 function configure_monasca_log_api_mod_wsgi {
  249     sudo install -d $MONASCA_LOG_API_WSGI_DIR
  250 
  251     local monasca_log_api_apache_conf
  252     monasca_log_api_apache_conf=$(apache_site_config_for monasca-log-api)
  253 
  254     local monasca_log_api_ssl=""
  255     local monasca_log_api_certfile=""
  256     local monasca_log_api_keyfile=""
  257     local monasca_log_api_api_port=$MONASCA_LOG_API_SERVICE_PORT
  258     local venv_path=""
  259 
  260     if is_ssl_enabled_service monasca_log_api; then
  261         monasca_log_api_ssl="SSLEngine On"
  262         monasca_log_api_certfile="SSLCertificateFile $MONASCA_LOG_API_SSL_CERT"
  263         monasca_log_api_keyfile="SSLCertificateKeyFile $MONASCA_LOG_API_SSL_KEY"
  264     fi
  265     if is_service_enabled tls-proxy; then
  266         monasca_log_api_api_port=$MONASCA_LOG_API_SERVICE_PORT_INT
  267     fi
  268     if [[ ${USE_VENV} = True ]]; then
  269         venv_path="python-path=${PROJECT_VENV["monasca_log_api"]}/lib/$(python_version)/site-packages"
  270     fi
  271 
  272     # copy proxy vhost and wsgi helper files
  273     sudo cp $PLUGIN_FILES/apache-log-api.template $monasca_log_api_apache_conf
  274     sudo sed -e "
  275         s|%PUBLICPORT%|$monasca_log_api_api_port|g;
  276         s|%APACHE_NAME%|$APACHE_NAME|g;
  277         s|%PUBLICWSGI%|$MONASCA_LOG_API_BIN_DIR/monasca-log-api-wsgi|g;
  278         s|%SSLENGINE%|$monasca_log_api_ssl|g;
  279         s|%SSLCERTFILE%|$monasca_log_api_certfile|g;
  280         s|%SSLKEYFILE%|$monasca_log_api_keyfile|g;
  281         s|%USER%|$STACK_USER|g;
  282         s|%VIRTUALENV%|$venv_path|g
  283         s|%APIWORKERS%|$API_WORKERS|g
  284     " -i $monasca_log_api_apache_conf
  285 }
  286 
  287 function create_log_api_cache_dir {
  288     sudo install -m 700 -d -o $STACK_USER $MONASCA_LOG_API_CACHE_DIR
  289 }
  290 
  291 function clean_monasca_log_api {
  292     if is_service_enabled monasca-log-api; then
  293         echo_summary "Cleaning monasca-log-api"
  294 
  295         sudo rm -f $MONASCA_LOG_API_CONF || true
  296         sudo rm -f $MONASCA_LOG_API_PASTE  || true
  297         sudo rm -f $MONASCA_LOG_API_LOGGING_CONF || true
  298         sudo rm -rf $MONASCA_LOG_API_CACHE_DIR || true
  299         sudo rm -rf $MONASCA_LOG_API_CONF_DIR || true
  300 
  301         sudo rm -rf $MONASCA_LOG_API_DIR || true
  302 
  303         if [ "$MONASCA_LOG_API_USE_MOD_WSGI" == "True" ]; then
  304             clean_monasca_log_api_wsgi
  305         fi
  306     fi
  307 }
  308 
  309 function clean_monasca_log_api_wsgi {
  310     sudo rm -f $MONASCA_LOG_API_WSGI_DIR/*
  311     sudo rm -f $(apache_site_config_for monasca-log-api)
  312 }
  313 
  314 function start_monasca_log_api {
  315     if is_service_enabled monasca-log-api; then
  316         echo_summary "Starting monasca-log-api"
  317 
  318         local service_port=$MONASCA_LOG_API_SERVICE_PORT
  319         local service_protocol=$MONASCA_LOG_API_SERVICE_PROTOCOL
  320         if is_service_enabled tls-proxy; then
  321             service_port=$MONASCA_LOG_API_SERVICE_PORT_INT
  322             service_protocol="http"
  323         fi
  324         local service_uri
  325 
  326         if [ "$MONASCA_LOG_API_DEPLOY" == "mod_wsgi" ]; then
  327             local enabled_site_file
  328             enabled_site_file=$(apache_site_config_for monasca-log-api)
  329             service_uri=$service_protocol://$MONASCA_LOG_API_SERVICE_HOST/logs/v3.0
  330             if [ -f ${enabled_site_file} ]; then
  331                 enable_apache_site monasca-log-api
  332                 restart_apache_server
  333                 tail_log monasca-log-api /var/log/$APACHE_NAME/monasca-log-api.log
  334             fi
  335         elif [ "$MONASCA_LOG_API_DEPLOY" == "uwsgi" ]; then
  336             service_uri=$service_protocol://$MONASCA_LOG_API_SERVICE_HOST/logs/v3.0
  337             run_process "monasca-log-api" "$MONASCA_LOG_API_BIN_DIR/uwsgi --ini $MONASCA_LOG_API_UWSGI_CONF" ""
  338         else
  339             service_uri=$service_protocol://$MONASCA_LOG_API_SERVICE_HOST:$service_port
  340             run_process "monasca-log-api" "$MONASCA_LOG_API_BIN_DIR/gunicorn --paste $MONASCA_LOG_API_PASTE" ""
  341         fi
  342 
  343         echo "Waiting for monasca-log-api to start..."
  344         if ! wait_for_service $SERVICE_TIMEOUT $service_uri; then
  345             die $LINENO "monasca-log-api did not start"
  346         fi
  347 
  348         if is_service_enabled tls-proxy; then
  349             start_tls_proxy monasca-log-api '*' $MONASCA_LOG_API_SERVICE_PORT $MONASCA_LOG_API_SERVICE_HOST $MONASCA_LOG_API_SERVICE_PORT_INT
  350         fi
  351 
  352         restart_service memcached
  353     fi
  354 }
  355 
  356 function stop_monasca_log_api {
  357     if is_service_enabled monasca-log-api; then
  358         if [ "$MONASCA_LOG_API_DEPLOY" == "mod_wsgi" ]; then
  359             disable_apache_site monasca-log-api
  360             restart_apache_server
  361         else
  362             stop_process "monasca-log-api"
  363             if [ "$MONASCA_LOG_API_DEPLOY" == "uwsgi" ]; then
  364                 remove_uwsgi_config  "$MONASCA_LOG_API_UWSGI_CONF" "$MONASCA_LOG_API_WSGI"
  365             fi
  366         fi
  367     fi
  368 }
  369 
  370 function install_logstash {
  371     if is_logstash_required; then
  372         echo_summary "Installing Logstash ${LOGSTASH_VERSION}"
  373 
  374         local logstash_tarball=logstash-${LOGSTASH_VERSION}.tar.gz
  375         local logstash_url=http://download.elastic.co/logstash/logstash/${logstash_tarball}
  376 
  377         local logstash_dest
  378         logstash_dest=`get_extra_file ${logstash_url}`
  379 
  380         tar xzf ${logstash_dest} -C $DEST
  381 
  382         sudo chown -R $STACK_USER $DEST/logstash-${LOGSTASH_VERSION}
  383         ln -sf $DEST/logstash-${LOGSTASH_VERSION} $LOGSTASH_DIR
  384     fi
  385 }
  386 
  387 function clean_logstash {
  388     if is_logstash_required; then
  389         echo_summary "Cleaning Logstash ${LOGSTASH_VERSION}"
  390 
  391         sudo rm -rf $LOGSTASH_DIR || true
  392         sudo rm -rf $FILES/logstash-${LOGSTASH_VERSION}.tar.gz ||  true
  393         sudo rm -rf $DEST/logstash-${LOGSTASH_VERSION} || true
  394     fi
  395 }
  396 
  397 function install_elasticsearch {
  398     if is_service_enabled elasticsearch; then
  399         echo_summary "Installing ElasticSearch ${ELASTICSEARCH_VERSION}"
  400 
  401         local es_tarball=elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz
  402         local es_url=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/${ELASTICSEARCH_VERSION}/${es_tarball}
  403 
  404         local es_dest
  405         es_dest=`get_extra_file ${es_url}`
  406 
  407         tar xzf ${es_dest} -C $DEST
  408 
  409         sudo chown -R $STACK_USER $DEST/elasticsearch-${ELASTICSEARCH_VERSION}
  410         ln -sf $DEST/elasticsearch-${ELASTICSEARCH_VERSION} $ELASTICSEARCH_DIR
  411     fi
  412 }
  413 
  414 function configure_elasticsearch {
  415     if is_service_enabled elasticsearch; then
  416         echo_summary "Configuring ElasticSearch ${ELASTICSEARCH_VERSION}"
  417 
  418         local templateDir=$ELASTICSEARCH_CFG_DIR/templates
  419 
  420         for dir in $ELASTICSEARCH_LOG_DIR $templateDir $ELASTICSEARCH_DATA_DIR; do
  421             sudo install -m 755 -d -o $STACK_USER $dir
  422         done
  423 
  424         sudo cp -f "${PLUGIN_FILES}"/elasticsearch/elasticsearch.yml $ELASTICSEARCH_CFG_DIR/elasticsearch.yml
  425         sudo chown -R $STACK_USER $ELASTICSEARCH_CFG_DIR/elasticsearch.yml
  426         sudo chmod 0644 $ELASTICSEARCH_CFG_DIR/elasticsearch.yml
  427 
  428         sudo sed -e "
  429             s|%ES_SERVICE_BIND_HOST%|$ES_SERVICE_BIND_HOST|g;
  430             s|%ES_SERVICE_BIND_PORT%|$ES_SERVICE_BIND_PORT|g;
  431             s|%ES_SERVICE_PUBLISH_HOST%|$ES_SERVICE_PUBLISH_HOST|g;
  432             s|%ES_SERVICE_PUBLISH_PORT%|$ES_SERVICE_PUBLISH_PORT|g;
  433             s|%ES_DATA_DIR%|$ELASTICSEARCH_DATA_DIR|g;
  434             s|%ES_LOG_DIR%|$ELASTICSEARCH_LOG_DIR|g;
  435         " -i $ELASTICSEARCH_CFG_DIR/elasticsearch.yml
  436 
  437         ln -sf $ELASTICSEARCH_CFG_DIR/elasticsearch.yml $GATE_CONFIGURATION_DIR/elasticsearch.yml
  438     fi
  439 }
  440 
  441 function clean_elasticsearch {
  442     if is_service_enabled elasticsearch; then
  443         echo_summary "Cleaning Elasticsearch ${ELASTICSEARCH_VERSION}"
  444 
  445         sudo rm -rf ELASTICSEARCH_DIR || true
  446         sudo rm -rf ELASTICSEARCH_CFG_DIR || true
  447         sudo rm -rf ELASTICSEARCH_LOG_DIR || true
  448         sudo rm -rf ELASTICSEARCH_DATA_DIR || true
  449         sudo rm -rf $FILES/elasticsearch-${ELASTICSEARCH_VERSION}.tar.gz || true
  450         sudo rm -rf $DEST/elasticsearch-${ELASTICSEARCH_VERSION} || true
  451     fi
  452 }
  453 
  454 function start_elasticsearch {
  455     if is_service_enabled elasticsearch; then
  456         echo_summary "Starting ElasticSearch ${ELASTICSEARCH_VERSION}"
  457         # 5 extra seconds to ensure that ES started properly
  458         local esSleepTime=${ELASTICSEARCH_SLEEP_TIME:-5}
  459         run_process_sleep "elasticsearch" "$ELASTICSEARCH_DIR/bin/elasticsearch" $esSleepTime
  460     fi
  461 }
  462 
  463 function install_kibana {
  464     if is_service_enabled kibana; then
  465         echo_summary "Installing Kibana ${KIBANA_VERSION}"
  466 
  467         local kibana_tarball=kibana-${KIBANA_VERSION}.tar.gz
  468         local kibana_tarball_url=http://download.elastic.co/kibana/kibana/${kibana_tarball}
  469 
  470         local kibana_tarball_dest
  471         kibana_tarball_dest=`get_extra_file ${kibana_tarball_url}`
  472 
  473         tar xzf ${kibana_tarball_dest} -C $DEST
  474 
  475         sudo chown -R $STACK_USER $DEST/kibana-${KIBANA_VERSION}
  476         ln -sf $DEST/kibana-${KIBANA_VERSION} $KIBANA_DIR
  477     fi
  478 }
  479 
  480 function configure_kibana {
  481     if is_service_enabled kibana; then
  482         echo_summary "Configuring Kibana ${KIBANA_VERSION}"
  483 
  484         sudo install -m 755 -d -o $STACK_USER $KIBANA_CFG_DIR
  485 
  486         sudo cp -f "${PLUGIN_FILES}"/kibana/kibana.yml $KIBANA_CFG_DIR/kibana.yml
  487         sudo chown -R $STACK_USER $KIBANA_CFG_DIR/kibana.yml
  488         sudo chmod 0644 $KIBANA_CFG_DIR/kibana.yml
  489 
  490         sudo sed -e "
  491             s|%KIBANA_SERVICE_HOST%|$KIBANA_SERVICE_HOST|g;
  492             s|%KIBANA_SERVICE_PORT%|$KIBANA_SERVICE_PORT|g;
  493             s|%KIBANA_SERVER_BASE_PATH%|$KIBANA_SERVER_BASE_PATH|g;
  494             s|%ES_SERVICE_BIND_HOST%|$ES_SERVICE_BIND_HOST|g;
  495             s|%ES_SERVICE_BIND_PORT%|$ES_SERVICE_BIND_PORT|g;
  496             s|%KEYSTONE_AUTH_URI%|$KEYSTONE_AUTH_URI|g;
  497         " -i $KIBANA_CFG_DIR/kibana.yml
  498 
  499         ln -sf $KIBANA_CFG_DIR/kibana.yml $GATE_CONFIGURATION_DIR/kibana.yml
  500     fi
  501 }
  502 
  503 function install_kibana_plugin {
  504     if is_service_enabled kibana; then
  505         echo_summary "Install Kibana plugin"
  506 
  507         # note(trebskit) that needs to happen after kibana received
  508         # its configuration otherwise the plugin fails to be installed
  509 
  510         local pkg=file://$DEST/monasca-kibana-plugin.tar.gz
  511 
  512         $KIBANA_DIR/bin/kibana plugin -r monasca-kibana-plugin
  513         $KIBANA_DIR/bin/kibana plugin -i monasca-kibana-plugin -u $pkg
  514     fi
  515 }
  516 
  517 function clean_kibana {
  518     if is_service_enabled kibana; then
  519         echo_summary "Cleaning Kibana ${KIBANA_VERSION}"
  520 
  521         sudo rm -rf $KIBANA_DIR || true
  522         sudo rm -rf $FILES/kibana-${KIBANA_VERSION}.tar.gz || true
  523         sudo rm -rf $KIBANA_CFG_DIR || true
  524     fi
  525 }
  526 
  527 function start_kibana {
  528     if is_service_enabled kibana; then
  529         echo_summary "Starting Kibana ${KIBANA_VERSION}"
  530         local kibanaSleepTime=${KIBANA_SLEEP_TIME:-90}     # kibana takes some time to load up
  531         local kibanaCFG="$KIBANA_CFG_DIR/kibana.yml"
  532         run_process_sleep "kibana" "$KIBANA_DIR/bin/kibana --config $kibanaCFG" $kibanaSleepTime
  533     fi
  534 }
  535 
  536 function configure_monasca_log_persister {
  537     if is_service_enabled monasca-log-persister; then
  538         echo_summary "Configuring monasca-log-persister"
  539 
  540         sudo install -m 755 -d -o $STACK_USER $LOG_PERSISTER_DIR
  541 
  542         sudo cp -f "${PLUGIN_FILES}"/monasca-log-persister/persister.conf $LOG_PERSISTER_DIR/persister.conf
  543         sudo chown $STACK_USER $LOG_PERSISTER_DIR/persister.conf
  544         sudo chmod 0640 $LOG_PERSISTER_DIR/persister.conf
  545 
  546         sudo sed -e "
  547             s|%ES_SERVICE_BIND_HOST%|$ES_SERVICE_BIND_HOST|g;
  548         " -i $LOG_PERSISTER_DIR/persister.conf
  549 
  550         ln -sf $LOG_PERSISTER_DIR/persister.conf $GATE_CONFIGURATION_DIR/log-persister.conf
  551     fi
  552 }
  553 
  554 function clean_monasca_log_persister {
  555     if is_service_enabled monasca-log-persister; then
  556         echo_summary "Cleaning monasca-log-persister"
  557         sudo rm -rf $LOG_PERSISTER_DIR || true
  558     fi
  559 }
  560 
  561 function start_monasca_log_persister {
  562     if is_service_enabled monasca-log-persister; then
  563         echo_summary "Starting monasca-log-persister"
  564         local logstash="$LOGSTASH_DIR/bin/logstash"
  565         run_process "monasca-log-persister" "$logstash -f $LOG_PERSISTER_DIR/persister.conf"
  566     fi
  567 }
  568 
  569 function configure_monasca_log_transformer {
  570     if is_service_enabled monasca-log-transformer; then
  571         echo_summary "Configuring monasca-log-transformer"
  572 
  573         sudo install -m 755 -d -o $STACK_USER $LOG_TRANSFORMER_DIR
  574 
  575         sudo cp -f "${PLUGIN_FILES}"/monasca-log-transformer/transformer.conf $LOG_TRANSFORMER_DIR/transformer.conf
  576         sudo chown $STACK_USER $LOG_TRANSFORMER_DIR/transformer.conf
  577         sudo chmod 0640 $LOG_TRANSFORMER_DIR/transformer.conf
  578 
  579         sudo sed -e "
  580             s|%KAFKA_SERVICE_HOST%|$KAFKA_SERVICE_HOST|g;
  581             s|%KAFKA_SERVICE_PORT%|$KAFKA_SERVICE_PORT|g;
  582         " -i $LOG_TRANSFORMER_DIR/transformer.conf
  583 
  584         ln -sf $LOG_TRANSFORMER_DIR/transformer.conf $GATE_CONFIGURATION_DIR/log-transformer.conf
  585     fi
  586 }
  587 
  588 function clean_monasca_log_transformer {
  589     if is_service_enabled monasca-log-transformer; then
  590         echo_summary "Cleaning monasca-log-transformer"
  591         sudo rm -rf $LOG_TRANSFORMER_DIR || true
  592     fi
  593 }
  594 
  595 function start_monasca_log_transformer {
  596     if is_service_enabled monasca-log-transformer; then
  597         echo_summary "Starting monasca-log-transformer"
  598         local logstash="$LOGSTASH_DIR/bin/logstash"
  599         run_process "monasca-log-transformer" "$logstash -f $LOG_TRANSFORMER_DIR/transformer.conf"
  600     fi
  601 }
  602 
  603 function configure_monasca_log_metrics {
  604     if is_service_enabled monasca-log-metrics; then
  605         echo_summary "Configuring monasca-log-metrics"
  606 
  607         sudo install -m 755 -d -o $STACK_USER $LOG_METRICS_DIR
  608 
  609         sudo cp -f "${PLUGIN_FILES}"/monasca-log-metrics/log-metrics.conf $LOG_METRICS_DIR/log-metrics.conf
  610         sudo chown $STACK_USER $LOG_METRICS_DIR/log-metrics.conf
  611         sudo chmod 0640 $LOG_METRICS_DIR/log-metrics.conf
  612 
  613         sudo sed -e "
  614             s|%KAFKA_SERVICE_HOST%|$KAFKA_SERVICE_HOST|g;
  615             s|%KAFKA_SERVICE_PORT%|$KAFKA_SERVICE_PORT|g;
  616         " -i $LOG_METRICS_DIR/log-metrics.conf
  617 
  618         ln -sf $LOG_METRICS_DIR/log-metrics.conf $GATE_CONFIGURATION_DIR/log-metrics.conf
  619     fi
  620 }
  621 
  622 function clean_monasca_log_metrics {
  623     if is_service_enabled monasca-log-metrics; then
  624         echo_summary "Cleaning monasca-log-metrics"
  625         sudo rm -rf $LOG_METRICS_DIR || true
  626     fi
  627 }
  628 
  629 function start_monasca_log_metrics {
  630     if is_service_enabled monasca-log-metrics; then
  631         echo_summary "Starting monasca-log-metrics"
  632         local logstash="$LOGSTASH_DIR/bin/logstash"
  633         run_process "monasca-log-metrics" "$logstash -f $LOG_METRICS_DIR/log-metrics.conf"
  634     fi
  635 }
  636 
  637 function install_log_agent {
  638     if is_service_enabled monasca-log-agent; then
  639         echo_summary "Installing monasca-log-agent [monasca-output-plugin]"
  640 
  641         $LOGSTASH_DIR/bin/plugin install --version \
  642             "${LOGSTASH_OUTPUT_MONASCA_VERSION}" logstash-output-monasca_log_api
  643     fi
  644 }
  645 
  646 function configure_monasca_log_agent {
  647     if is_service_enabled monasca-log-agent; then
  648         echo_summary "Configuring monasca-log-agent"
  649 
  650         sudo install -m 755 -d -o $STACK_USER $LOG_AGENT_DIR
  651 
  652         sudo cp -f "${PLUGIN_FILES}"/monasca-log-agent/agent.conf $LOG_AGENT_DIR/agent.conf
  653         sudo chown $STACK_USER $LOG_AGENT_DIR/agent.conf
  654         sudo chmod 0640 $LOG_AGENT_DIR/agent.conf
  655 
  656         sudo sed -e "
  657             s|%MONASCA_LOG_API_URI_V3%|$MONASCA_LOG_API_URI_V3|g;
  658             s|%KEYSTONE_AUTH_URI_V3%|$KEYSTONE_AUTH_URI_V3|g;
  659         " -i $LOG_AGENT_DIR/agent.conf
  660 
  661         ln -sf $LOG_AGENT_DIR/agent.conf $GATE_CONFIGURATION_DIR/log-agent.conf
  662 
  663     fi
  664 }
  665 
  666 function clean_monasca_log_agent {
  667     if is_service_enabled monasca-log-agent; then
  668         echo_summary "Cleaning monasca-log-agent"
  669         sudo rm -rf $LOG_AGENT_DIR || true
  670     fi
  671 }
  672 
  673 function start_monasca_log_agent {
  674     if is_service_enabled monasca-log-agent; then
  675         echo_summary "Starting monasca-log-agent"
  676         local logstash="$LOGSTASH_DIR/bin/logstash"
  677         run_process "monasca-log-agent" "$logstash -f $LOG_AGENT_DIR/agent.conf" "root" "root"
  678     fi
  679 }
  680 
  681 function install_nodejs {
  682     if is_service_enabled kibana; then
  683         # refresh installation
  684         apt_get install nodejs npm
  685         (
  686             npm config set registry "http://registry.npmjs.org/"; \
  687             npm config set proxy "${HTTP_PROXY}"; \
  688             npm set strict-ssl false;
  689         )
  690     fi
  691 }
  692 
  693 function clean_nodejs {
  694     if is_service_enabled kibana; then
  695         echo_summary "Cleaning Node.js"
  696         apt_get purge nodejs npm
  697     fi
  698 }
  699 
  700 function clean_gate_config_holder {
  701     sudo rm -rf $GATE_CONFIGURATION_DIR || true
  702 }
  703 
  704 function build_kibana_plugin {
  705     if is_service_enabled kibana; then
  706         echo "Building Kibana plugin"
  707 
  708         git_clone $MONASCA_KIBANA_PLUGIN_REPO $MONASCA_KIBANA_PLUGIN_DIR \
  709             $MONASCA_KIBANA_PLUGIN_BRANCH
  710 
  711         pushd $MONASCA_KIBANA_PLUGIN_DIR
  712 
  713         local monasca_kibana_plugin_version
  714         monasca_kibana_plugin_version="$(python -c 'import json; \
  715             obj = json.load(open("package.json")); print obj["version"]')"
  716 
  717         npm install
  718         npm run package
  719 
  720         local pkg=$MONASCA_KIBANA_PLUGIN_DIR/target/monasca-kibana-plugin-${monasca_kibana_plugin_version}.tar.gz
  721         local easyPkg=$DEST/monasca-kibana-plugin.tar.gz
  722 
  723         ln -sf $pkg $easyPkg
  724 
  725         popd
  726     fi
  727 }
  728 
  729 function configure_kafka {
  730     echo_summary "Configuring Kafka topics"
  731     /opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 \
  732         --replication-factor 1 --partitions 4 --topic log
  733     /opt/kafka/bin/kafka-topics.sh --create --zookeeper localhost:2181 \
  734         --replication-factor 1 --partitions 4 --topic transformed-log
  735 }
  736 
  737 function delete_kafka_topics {
  738     echo_summary "Deleting Kafka topics"
  739         /opt/kafka/bin/kafka-topics.sh --delete --zookeeper localhost:2181 \
  740                 --topic log || true
  741         /opt/kafka/bin/kafka-topics.sh --delete --zookeeper localhost:2181 \
  742                 --topic transformed-log || true
  743 }
  744 
  745 function create_log_management_accounts {
  746     if is_service_enabled monasca-log-api; then
  747         echo_summary "Enable Log Management in Keystone"
  748 
  749         # note(trebskit) following points to Kibana which is bad,
  750         # but we do not have search-api in monasca-log-api now
  751         # this code will be removed in future
  752         local log_search_url="http://$KIBANA_SERVICE_HOST:$KIBANA_SERVICE_PORT/"
  753 
  754         get_or_create_service "logs" "logs" "Monasca Log service"
  755         get_or_create_endpoint \
  756             "logs" \
  757             "$REGION_NAME" \
  758             "$MONASCA_LOG_API_URI_V3" \
  759             "$MONASCA_LOG_API_URI_V3" \
  760             "$MONASCA_LOG_API_URI_V3"
  761 
  762         get_or_create_service "logs_v2" "logs_v2" "Monasca Log V2.0 service"
  763         get_or_create_endpoint \
  764             "logs_v2" \
  765             "$REGION_NAME" \
  766             "$MONASCA_LOG_API_URI_V2" \
  767             "$MONASCA_LOG_API_URI_V2" \
  768             "$MONASCA_LOG_API_URI_V2"
  769 
  770         get_or_create_service "logs-search" "logs-search" "Monasca Log search service"
  771         get_or_create_endpoint \
  772             "logs-search" \
  773             "$REGION_NAME" \
  774             "$log_search_url" \
  775             "$log_search_url" \
  776             "$log_search_url"
  777 
  778     fi
  779 }
  780 
  781 function enable_log_management {
  782     if is_service_enabled horizon && is_service_enabled kibana; then
  783         echo_summary "Configure Horizon with Kibana access"
  784 
  785         local localSettings=${DEST}/horizon/monitoring/config/local_settings.py
  786 
  787         sudo sed -e "
  788             s|KIBANA_HOST = getattr(settings, 'KIBANA_HOST', 'http://192.168.10.4:5601/')|KIBANA_HOST = getattr(settings, 'KIBANA_HOST', 'http://${KIBANA_SERVICE_HOST}:${KIBANA_SERVICE_PORT}/')|g;
  789         " -i ${localSettings}
  790 
  791         if is_service_enabled monasca-log-api; then
  792             sudo sed -e "
  793                 s|'ENABLE_LOG_MANAGEMENT_BUTTON', False|'ENABLE_LOG_MANAGEMENT_BUTTON', True|g;
  794             " -i ${localSettings}
  795         fi
  796 
  797         restart_apache_server
  798     fi
  799 }
  800 
  801 # check for service enabled
  802 if is_service_enabled monasca-log; then
  803 
  804     if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then
  805         # Set up system services
  806         echo_summary "Configuring Monasca Log Management system services"
  807         pre_install
  808 
  809     elif [[ "$1" == "stack" && "$2" == "install" ]]; then
  810         # Perform installation of service source
  811         echo_summary "Installing Monasca Log Management"
  812         install_monasca_log
  813 
  814     elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
  815         # Configure after the other layer 1 and 2 services have been configured
  816         echo_summary "Configuring Monasca Log Management"
  817         configure_monasca_log
  818 
  819     elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
  820         # Initialize and start the Monasca service
  821         echo_summary "Initializing Monasca Log Management"
  822         init_monasca_log
  823         init_monasca_grafana_dashboards
  824         if is_service_enabled monasca-agent; then
  825             init_agent
  826         fi
  827         start_monasca_log
  828     fi
  829 
  830     if [[ "$1" == "unstack" ]]; then
  831         # Shut down Monasca services
  832         echo_summary "Unstacking Monasca Log Management"
  833         stop_monasca_log
  834         delete_kafka_topics
  835     fi
  836 
  837     if [[ "$1" == "clean" ]]; then
  838         # Remove state and transient data
  839         # Remember clean.sh first calls unstack.sh
  840         echo_summary "Cleaning Monasca Log Management"
  841         clean_monasca_log
  842     fi
  843 fi
  844 
  845 #Restore errexit
  846 $_ERREXIT_LOG_API
  847 
  848 # Restore xtrace
  849 $_XTRACE_LOG_API