Use devstack utilities for monasca-notification

Adjust monasca-notification installation with changes:
- start/stop of monasca-notification proces handles through run_process
  and stop_process and no service files
- setting up environment with devstack function
- use USE_VENV for monasca-notification
- installing monasca-notification dependencies from git
- remove service file from devstack/files/monasca-notification

Also added code from Idbe5bdf56fb280412c34f04de8f2e2f301a7a432

Depends-On: Idbe5bdf56fb280412c34f04de8f2e2f301a7a432
Change-Id: Ic581fbdd2db57c9a2f13f1646eb9485c5dd0f62b
This commit is contained in:
Tomasz Trębski 2017-06-29 07:02:14 +02:00
parent 175577d35b
commit f9b41eefbe
5 changed files with 164 additions and 159 deletions

View File

@ -1,30 +0,0 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Startup script for the monasca_notification
[Unit]
Description=Monasca Notification daemon
Requires=network.target
After=network.target kafka.service mysql.service
[Service]
User=mon-notification
Group=monasca
TimeoutStopSec=240
ExecStart=/opt/monasca/bin/monasca-notification
Restart=on-failure
[Install]
WantedBy=multi-user.target

View File

@ -89,6 +89,9 @@ zookeeper:
60: /notification/60_seconds
logging: # Used in logging.dictConfig
# This sets logging.raiseExcetpions. It is recommended to leave this set to False.
# See https://docs.python.org/2/howto/logging.html#exceptions-raised-during-logging
raise_exceptions: False
version: 1
disable_existing_loggers: False
formatters:
@ -100,7 +103,7 @@ logging: # Used in logging.dictConfig
formatter: default
file:
class: logging.handlers.RotatingFileHandler
filename: "/var/log/monasca/notification/notification.log"
filename: "%MONASCA_NOTIFICATION_LOG_DIR%/notification.log"
formatter: default
maxBytes: 10485760 # Rotate at file size ~10MB
backupCount: 5 # Keep 5 older logs around

View File

@ -0,0 +1,146 @@
#!/bin/bash
# Copyright 2017 FUJITSU LIMITED
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless reqmonasca_notificationred by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
_XTRACE_MON_NOTIFICATION=$(set +o | grep xtrace)
set +o xtrace
MONASCA_NOTIFICATION_CONF_DIR=${MONASCA_NOTIFICATION_CONF_DIR:-/etc/monasca}
MONASCA_NOTIFICATION_LOG_DIR=${MONASCA_NOTIFICATION_LOG_DIR:-/var/log/monasca/notification}
MONASCA_NOTIFICATION_CONF=${MONASCA_NOTIFICATION_CONF:-$MONASCA_NOTIFICATION_CONF_DIR/notification.yaml}
MONASCA_NOTIFICATION_GATE_CFG_LINK=/etc/monasca-notification
if [[ ${USE_VENV} = True ]]; then
PROJECT_VENV["monasca-notification"]=${MONASCA_NOTIFICATION_DIR}.venv
MONASCA_NOTIFICATION_BIN_DIR=${PROJECT_VENV["monasca-notification"]}/bin
else
MONASCA_NOTIFICATION_BIN_DIR=$(get_python_exec_prefix)
fi
is_monasca_notification_enabled() {
is_service_enabled monasca-notification && return 0
return 1
}
# NOTE(trebskit) ref: stack_install_service from devstack
install_monasca-notification() {
echo_summary "Installing monasca-notification"
git_clone ${MONASCA_NOTIFICATION_REPO} ${MONASCA_NOTIFICATION_DIR} \
${MONASCA_NOTIFICATION_BRANCH}
setup_develop ${MONASCA_NOTIFICATION_DIR}
# see devstack/plugin.sh
install_monasca_common
install_monasca_statsd
# see devstack/plugin.sh
if is_service_enabled postgresql; then
apt_get -y install libpq-dev
pip_install_gr psycopg2
elif is_service_enabled mysql; then
apt_get -y install python-mysqldb libmysqlclient-dev
pip_install_gr PyMySQL
pip_install_gr mysql-python
fi
if [[ ${MONASCA_DATABASE_USE_ORM} == "True" ]]; then
pip_install_gr sqlalchemy
fi
}
configure_monasca_notification() {
if ! is_monasca_notification_enabled; then
return
fi
echo_summary "Configuring monasca-notification"
sudo install -d -o $STACK_USER ${MONASCA_NOTIFICATION_CONF_DIR}
sudo install -d -o $STACK_USER ${MONASCA_NOTIFICATION_LOG_DIR}
install -m 600 ${MONASCA_API_DIR}/devstack/files/monasca-notification/notification.yaml ${MONASCA_NOTIFICATION_CONF}
local dbDriver
local dbEngine
local dbPort
if is_service_enabled postgresql; then
dbDriver="monasca_notification.common.repositories.postgres.pgsql_repo:PostgresqlRepo"
dbEngine="postgres"
dbPort=5432
else
dbDriver="monasca_notification.common.repositories.mysql.mysql_repo:MysqlRepo"
dbEngine="mysql"
dbPort=3306
fi
if [[ ${MONASCA_DATABASE_USE_ORM} == "True" ]]; then
dbDriver="monasca_notification.common.repositories.orm.orm_repo:OrmRepo"
fi
sudo sed -e "
s|%DATABASE_HOST%|${DATABASE_HOST}|g;
s|%DATABASE_PORT%|$dbPort|g;
s|%DATABASE_PASSWORD%|${DATABASE_PASSWORD}|g;
s|%DATABASE_USER%|${DATABASE_USER}|g;
s|%MONASCA_NOTIFICATION_DATABASE_DRIVER%|$dbDriver|g;
s|%MONASCA_NOTIFICATION_DATABASE_ENGINE%|$dbEngine|g;
s|%KAFKA_HOST%|${SERVICE_HOST}|g;
s|%MONASCA_STATSD_PORT%|${MONASCA_STATSD_PORT}|g;
s|%MONASCA_NOTIFICATION_LOG_DIR%|${MONASCA_NOTIFICATION_LOG_DIR}|g;
" -i ${MONASCA_NOTIFICATION_CONF}
sudo install -d -o ${STACK_USER} ${MONASCA_NOTIFICATION_GATE_CFG_LINK}
ln -sf ${MONASCA_NOTIFICATION_CONF} ${MONASCA_NOTIFICATION_GATE_CFG_LINK}
echo "postfix postfix/mailname string localhost" | sudo debconf-set-selections -v
echo "postfix postfix/main_mailer_type string 'Local only'" | sudo debconf-set-selections -v
}
start_monasca_notification(){
if is_monasca_notification_enabled; then
echo_summary "Starting monasca-notification"
run_process "monasca-notification" "$MONASCA_NOTIFICATION_BIN_DIR/monasca-notification $MONASCA_NOTIFICATION_CONF"
fi
}
stop_monasca_notification(){
if is_monasca_notification_enabled; then
echo_summary "Stopping monasca-notification"
stop_process "monasca-notification" || true
fi
}
clean_monasca_notification() {
if ! is_monasca_notification_enabled; then
return
fi
echo_summary "Configuring monasca-notification"
sudo rm -rf ${MONASCA_NOTIFICATION_CONF} ${MONASCA_NOTIFICATION_CONF_DIR} \
${MONASCA_NOTIFICATION_LOG_DIR} \
${MONASCA_NOTIFICATION_GATE_CFG_LINK}
if is_service_enabled postgresql; then
apt_get -y purge libpq-dev
elif is_service_enabled mysql; then
apt_get -y purge libmysqlclient-dev
apt_get -y purge python-mysqldb
fi
}
${_XTRACE_MON_NOTIFICATION}

View File

@ -47,6 +47,7 @@ set -o errexit
# source lib/*
source ${MONASCA_API_DIR}/devstack/lib/zookeeper.sh
source ${MONASCA_API_DIR}/devstack/lib/ui.sh
source ${MONASCA_API_DIR}/devstack/lib/notification.sh
# source lib/*
# Set default implementations to python
@ -80,13 +81,15 @@ else
fi
# monasca-api settings
# venv settings
if [[ ${USE_VENV} = True ]]; then
PROJECT_VENV["monasca-api"]=${MONASCA_API_DIR}.venv
MONASCA_API_BIN_DIR=${PROJECT_VENV["monasca-api"]}/bin
else
MONASCA_API_BIN_DIR=$(get_python_exec_prefix)
fi
# monasca-api settings
MONASCA_API_BASE_URI=${MONASCA_API_SERVICE_PROTOCOL}://${MONASCA_API_SERVICE_HOST}:${MONASCA_API_SERVICE_PORT}
MONASCA_API_URI_V2=${MONASCA_API_BASE_URI}/v2.0
@ -123,15 +126,16 @@ function install_monasca {
install_monasca_persister_$MONASCA_PERSISTER_IMPLEMENTATION_LANG
sudo systemctl enable monasca-persister
fi
if is_service_enabled monasca-notification; then
install_monasca_notification
fi
stack_install_service monasca-notification
if is_service_enabled monasca-thresh; then
if ! is_service_enabled monasca-storm; then
die "monasca-thresh requires monasca-storm service to be enabled"
fi
install_monasca_thresh
fi
if is_service_enabled monasca-api; then
if [ "$MONASCA_API_IMPLEMENTATION_LANG" == "python" ]; then
stack_install_service monasca-api
@ -152,6 +156,7 @@ function configure_monasca {
install_schema
configure_ui
configure_monasca_api
configure_monasca_notification
configure_screen
}
@ -160,8 +165,6 @@ function configure_screen {
sudo ln -sf /var/log/influxdb/influxd.log ${SCREEN_LOGDIR}/screen-influxdb.log || true
sudo ln -sf /var/log/monasca/persister/persister.log ${SCREEN_LOGDIR}/screen-monasca-persister.log || true
sudo ln -sf /var/log/monasca/notification/notification.log ${SCREEN_LOGDIR}/screen-monasca-notification.log || true
sudo ln -sf /var/log/monasca/agent/statsd.log ${SCREEN_LOGDIR}/screen-monasca-agent-statsd.log || true
sudo ln -sf /var/log/monasca/agent/supervisor.log ${SCREEN_LOGDIR}/screen-monasca-agent-supervisor.log || true
sudo ln -sf /var/log/monasca/agent/collector.log ${SCREEN_LOGDIR}/screen-monasca-agent-collector.log || true
@ -201,9 +204,7 @@ function start_monasca_services {
if is_service_enabled monasca-persister; then
start_service monasca-persister || restart_service monasca-persister
fi
if is_service_enabled monasca-notification; then
start_service monasca-notification || restart_service monasca-notification
fi
start_monasca_notification
if is_service_enabled monasca-thresh; then
start_service monasca-thresh || restart_service monasca-thresh
fi
@ -227,7 +228,7 @@ function unstack_monasca {
stop_service storm-nimbus || true
stop_service monasca-notification || true
stop_monasca_notification
stop_service monasca-persister || true
@ -266,9 +267,6 @@ function clean_monasca {
if is_service_enabled monasca-storm; then
clean_storm
fi
if is_service_enabled monasca-notification; then
clean_monasca_notification
fi
if is_service_enabled monasca-persister; then
clean_monasca_persister_$MONASCA_PERSISTER_IMPLEMENTATION_LANG
fi
@ -276,6 +274,8 @@ function clean_monasca {
clean_monasca_api_$MONASCA_API_IMPLEMENTATION_LANG
fi
clean_monasca_notification
clean_monasca_common_java
clean_schema
@ -1182,120 +1182,6 @@ function clean_monasca_persister_python {
sudo userdel mon-persister
}
function install_monasca_notification {
echo_summary "Install Monasca monasca_notification"
git_clone $MONASCA_NOTIFICATION_REPO $MONASCA_NOTIFICATION_DIR $MONASCA_NOTIFICATION_BRANCH
PIP_VIRTUAL_ENV=/opt/monasca
if is_service_enabled postgresql; then
apt_get -y install libpq-dev
pip_install_gr psycopg2
elif is_service_enabled mysql; then
apt_get -y install python-mysqldb libmysqlclient-dev
pip_install_gr PyMySQL
pip_install_gr mysql-python
fi
if [[ ${MONASCA_DATABASE_USE_ORM} == "True" ]]; then
pip_install_gr sqlalchemy
fi
setup_install $MONASCA_NOTIFICATION_DIR
install_monasca_common
install_monasca_statsd
unset PIP_VIRTUAL_ENV
sudo useradd --system -g monasca mon-notification || true
sudo mkdir -p /var/log/monasca/notification || true
sudo chown root:monasca /var/log/monasca/notification
sudo chmod 0775 /var/log/monasca/notification
sudo mkdir -p /etc/monasca || true
sudo chown root:monasca /etc/monasca
sudo chmod 0775 /etc/monasca
sudo cp -f "${MONASCA_API_DIR}"/devstack/files/monasca-notification/notification.yaml /etc/monasca/notification.yaml
sudo chown mon-notification:monasca /etc/monasca/notification.yaml
sudo chmod 0660 /etc/monasca/notification.yaml
local dbDriver
local dbEngine
local dbPort
if is_service_enabled postgresql; then
dbDriver="monasca_notification.common.repositories.postgres.pgsql_repo:PostgresqlRepo"
dbEngine="postgres"
dbPort=5432
else
dbDriver="monasca_notification.common.repositories.mysql.mysql_repo:MysqlRepo"
dbEngine="mysql"
dbPort=3306
fi
if [[ ${MONASCA_DATABASE_USE_ORM} == "True" ]]; then
dbDriver="monasca_notification.common.repositories.orm.orm_repo:OrmRepo"
fi
sudo sed -e "
s|%DATABASE_HOST%|$DATABASE_HOST|g;
s|%DATABASE_PORT%|$dbPort|g;
s|%DATABASE_PASSWORD%|$DATABASE_PASSWORD|g;
s|%DATABASE_USER%|$DATABASE_USER|g;
s|%MONASCA_NOTIFICATION_DATABASE_DRIVER%|$dbDriver|g;
s|%MONASCA_NOTIFICATION_DATABASE_ENGINE%|$dbEngine|g;
s|%KAFKA_HOST%|$SERVICE_HOST|g;
s|%MONASCA_STATSD_PORT%|$MONASCA_STATSD_PORT|g;
" -i /etc/monasca/notification.yaml
sudo cp -f "${MONASCA_API_DIR}"/devstack/files/monasca-notification/monasca-notification.service /etc/systemd/system/monasca-notification.service
sudo chown root:root /etc/systemd/system/monasca-notification.service
sudo chmod 0644 /etc/systemd/system/monasca-notification.service
sudo systemctl enable monasca-notification
sudo debconf-set-selections <<< "postfix postfix/mailname string localhost"
sudo debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Local only'"
}
function clean_monasca_notification {
echo_summary "Clean Monasca monasca_notification"
sudo systemctl disable monasca-notification
sudo rm /etc/systemd/system/monasca-notification.service
sudo rm /etc/monasca/notification.yaml
sudo rm -rf /var/log/monasca/notification
sudo userdel mon-notification
sudo rm -rf /opt/monasca/monasca-notification
sudo rm /var/log/upstart/monasca-notification.log*
if is_service_enabled postgresql; then
apt_get -y purge libpq-dev
elif is_service_enabled mysql; then
apt_get -y purge libmysqlclient-dev
apt_get -y purge python-mysqldb
fi
}
function install_storm {
echo_summary "Install Monasca Storm"

View File

@ -184,4 +184,4 @@ MONASCA_API_CONF=${MONASCA_API_CONF:-$MONASCA_API_CONF_DIR/api-config.conf}
MONASCA_API_PASTE_INI=${MONASCA_API_PASTE_INI:-$MONASCA_API_CONF_DIR/api-config.ini}
MONASCA_API_LOGGING_CONF=${MONASCA_API_LOGGING_CONF:-$MONASCA_API_CONF_DIR/api-logging.conf}
MONASCA_API_CACHE_DIR=${MONASCA_API_CACHE_DIR:-/var/cache/monasca-api}
MONASCA_API_LOG_DIR=${MONASCA_API_LOG_DIR:-/var/log/monasca/api}
MONASCA_API_LOG_DIR=${MONASCA_API_LOG_DIR:-/var/log/monasca/api}