fault/devstack/lib/stx-fault
Sun Austin 767cdc211c [devstack] change libfmcommon path to /usr/local/lib64
Change-Id: I7cb026a12518dfc56d9b0bb0b07a58362f1a8543
Signed-off-by: Sun Austin <austin.sun@intel.com>
2019-01-24 11:13:13 +08:00

316 lines
8.0 KiB
Bash

#!/bin/bash
#
# lib/stx-fault
# Functions to control the configuration and operation of the **fault** service
# Dependencies:
#
# - ``functions`` file
# - ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
# - The stx-update plugin must be enabled
# ``stack.sh`` calls the entry points in this order:
#
# - install_fault
# - configure_fault
# - init_fault
# - start_fault
# - stop_fault
# - cleanup_fault
_XTRACE_STX_FAULT=$(set +o | grep xtrace)
set -o xtrace
# Defaults
# --------
FAULT_DIR=${GITDIR[$STX_FAULT_NAME]}
FAULT_CONF_DIR=/etc/fm
FM_RESTAPI_CONF=$FAULT_CONF_DIR/fm.conf
FM_RESTAPI_PASTE_INI=$FAULT_CONF_DIR/api-paste.ini
FM_RESTAPI_AUTH_CACHE_DIR=${FM_RESTAPI_AUTH_CACHE_DIR:-/var/cache/fault}
FM_RESTAPI_DIR=${GITDIR[$STX_FAULT_NAME]}/fm-rest-api/fm
if is_service_enabled tls-proxy; then
FM_RESTAPI_SERVICE_PROTOCOL="https"
fi
FM_RESTAPI_SERVICE_PROTOCOL=${FM_RESTAPI_SERVICE_PROTOCOL:-$SERVICE_PROTOCOL}
FM_RESTAPI_SERVICE_HOST=${FM_RESTAPI_SERVICE_HOST:-$SERVICE_HOST}
FM_RESTAPI_SERVICE_PORT=${FM_RESTAPI_SERVICE_PORT:-18002}
FM_RESTAPI_WORKERS=${FM_RESTAPI_WORKERS:-4}
STX_BIN_DIR=$(get_python_exec_prefix)
PYTHON_SITE_DIR=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
# Functions
# ---------
function cleanup_fault {
stop_fault
if is_service_enabled fm-mgr; then
cleanup_fm_mgr
fi
if is_service_enabled fm-common; then
cleanup_fm_common
fi
if is_service_enabled fm-rest-api; then
cleanup_fm_rest_api
fi
}
function cleanup_fm_common {
local x version
# get fm-common version
read x version <<< $(grep '^Version: ' ${GITDIR[$STX_FAULT_NAME]}/fm-common/PKG-INFO)
local major=${version%%.*}
local minor=${version##*.}
local prefix=${STX_BIN_DIR%/*}
sudo rm /etc/ld.so.conf.d/stx-fault.conf
pushd ${GITDIR[$STX_FAULT_NAME]}/fm-common/sources
sudo make \
DEST_DIR=$prefix \
BIN_DIR=/bin \
LIB_DIR=/lib \
INC_DIR=/include \
MAJOR=$major \
MINOR=$minor \
clean
sudo rm $prefix/bin/fm_db_sync_event_suppression.py \
$prefix/include/fmConfig.h \
$prefix/include/fmLog.h
popd
}
function cleanup_fm_mgr {
local x version
# get fm-mgr version
read x version <<< $(grep '^Version: ' ${GITDIR[$STX_FAULT_NAME]}/fm-mgr/PKG-INFO)
local major=${version%%.*}
local minor=${version##*.}
pushd ${GITDIR[$STX_FAULT_NAME]}/fm-mgr/sources
sudo make \
BIN_DIR=/bin \
LIB_DIR=/lib \
INC_DIR=/include \
MAJOR=$major \
MINOR=$minor \
clean
popd
}
function cleanup_fm_rest_api {
sudo rm -rf $FM_RESTAPI_AUTH_CACHE_DIR $FM_RESTAPI_CONF
}
function configure_fault {
if is_service_enabled fm-rest-api; then
configure_fm_rest_api
fi
}
function configure_fm_rest_api {
sudo install -d -o $STACK_USER -m 755 $FAULT_CONF_DIR
cp -p $FAULT_DIR/devstack/files/api-paste.ini $FM_RESTAPI_PASTE_INI
configure_auth_token_middleware $FM_RESTAPI_CONF fm $FM_RESTAPI_AUTH_CACHE_DIR
iniset $FM_RESTAPI_CONF database connection $(database_connection_url fm)
iniset $FM_RESTAPI_CONF api api_paste_config $FM_RESTAPI_PASTE_INI
iniset $FM_RESTAPI_CONF api api_workers $FM_RESTAPI_WORKERS
iniset $FM_RESTAPI_CONF api bind_host $FM_RESTAPI_SERVICE_HOST
iniset $FM_RESTAPI_CONF api bind_port $FM_RESTAPI_SERVICE_PORT
iniset $FM_RESTAPI_CONF oslo_middleware enable_proxy_headers_parsing True
if [ "$SYSLOG" != "False" ]; then
iniset $FM_RESTAPI_CONF DEFAULT use_syslog True
# stx specific?
iniset $FM_RESTAPI_CONF DEFAULT syslog_log_facility local2
fi
# Additional things set in stx config
iniset $FM_RESTAPI_CONF DEFAULT region_name RegionOne
iniset $FM_RESTAPI_CONF DEFAULT event_log_max_size 4000
iniset $FM_RESTAPI_CONF DEFAULT system_name $(hostname)
iniset $FM_RESTAPI_CONF database idle_timeout 60
iniset $FM_RESTAPI_CONF database max_pool_size 1
iniset $FM_RESTAPI_CONF database max_overflow 20
iniset $FM_RESTAPI_CONF keystone_authtoken region_name RegionOne
# sysinv settings to move there...
iniset $FM_RESTAPI_CONF sysinv catalog_info platform:sysinv:internalURL
iniset $FM_RESTAPI_CONF sysinv os_region_name RegionOne
}
function create_fault_accounts {
if [[ "$ENABLED_SERVICES" =~ "fm-rest-api" ]]; then
create_service_user "fm"
get_or_create_service "fm" "faultmanagement" "Fault Management Service"
get_or_create_endpoint \
"faultmanagement" \
"$REGION_NAME" \
"$FM_RESTAPI_SERVICE_PROTOCOL://$FM_RESTAPI_SERVICE_HOST:$FM_RESTAPI_SERVICE_PORT/v1"
fi
}
function create_fault_cache_dir {
# Create cache dir
sudo install -d -o $STACK_USER $FM_RESTAPI_AUTH_CACHE_DIR
rm -f $FM_RESTAPI_AUTH_CACHE_DIR/*
}
function create_fault_user_group {
:
}
function init_fault {
create_fault_cache_dir
}
function install_fault {
if is_service_enabled fm-common; then
install_fm_common
install_fm_client
fi
if is_service_enabled fm-api; then
install_fm_api
fi
if is_service_enabled fm-api; then
install_fm_api
fi
if is_service_enabled fm-mgr; then
install_fm_mgr
fi
if is_service_enabled fm-rest-api; then
install_fm_rest_api
fi
}
function install_fm_api {
pushd ${GITDIR[$STX_FAULT_NAME]}/fm-api
sudo python setup.py install \
--root=/ \
--install-lib=$PYTHON_SITE_DIR \
--prefix=/usr \
--install-data=/usr/share \
--single-version-externally-managed
popd
}
function install_fm_client {
pushd ${GITDIR[$STX_FAULT_NAME]}/python-fmclient/fmclient
sudo python setup.py install \
--root=/ \
--install-lib=$PYTHON_SITE_DIR \
--prefix=/usr \
--install-data=/usr/share \
--single-version-externally-managed
popd
}
function install_fm_common {
local x version
# get fm-common version
read x version <<< $(grep '^Version: ' ${GITDIR[$STX_FAULT_NAME]}/fm-common/PKG-INFO)
local major=${version%%.*}
local minor=${version##*.}
# Set up the destinations
# Making an assumption here about STX_BIN_DIR having ../include be valid
local prefix=${STX_BIN_DIR%/*}
# build
pushd ${GITDIR[$STX_FAULT_NAME]}/fm-common/sources
make MAJOR=$major MINOR=$minor
sudo python setup.py build
# install
sudo make \
DEST_DIR=$prefix \
BIN_DIR=/bin \
LIB_DIR=/lib \
INC_DIR=/include \
MAJOR=$major \
MINOR=$minor \
install
sudo python setup.py install \
--root=/ \
--install-lib=$PYTHON_SITE_DIR \
--prefix=/usr \
--install-data=/usr/share \
# This _is_ nasty, clean it up
sudo install -m 755 fm_db_sync_event_suppression.py \
$prefix/bin/fm_db_sync_event_suppression.py
# install the headers that used by fm-mgr package
sudo install -m 644 -p -D fmConfig.h $prefix/include/fmConfig.h
sudo install -m 644 -p -D fmLog.h $prefix/include/fmLog.h
# Make sure we can find it later
# TODO: this should be managed better
echo /usr/local/lib64 | sudo tee /etc/ld.so.conf.d/stx-fault.conf
sudo ldconfig
popd
}
function install_fm_mgr {
local x version
# get fm-mgr version
read x version <<< $(grep '^Version: ' ${GITDIR[$STX_FAULT_NAME]}/fm-mgr/PKG-INFO)
local major=${version%%.*}
local minor=${version##*.}
# build
pushd ${GITDIR[$STX_FAULT_NAME]}/fm-mgr/sources
make MAJOR=$major MINOR=$minor
# install
sudo make \
BIN_DIR=/bin \
LIB_DIR=/lib \
INC_DIR=/include \
MAJOR=$major \
MINOR=$minor \
install
popd
}
function install_fm_rest_api {
setup_develop $FM_RESTAPI_DIR
}
function start_fault {
if is_service_enabled fm-api; then
run_process fm-api "$STX_BIN_DIR/fm-api --config-file $FM_RESTAPI_CONF"
fi
}
function stop_fault {
if is_service_enabled fm-api; then
stop_process fm_api
fi
}
$_XTRACE_STX_FAULT