Add common log and configuration places

Change-Id: Iacf294d42cd42680449f60837e8fcdd67d40ebcf
This commit is contained in:
Igor Yozhikov 2013-11-27 15:12:38 +04:00
parent a2935acc5f
commit d7f848c979
2 changed files with 125 additions and 97 deletions

View File

@ -25,6 +25,7 @@ GIT_CLONE_DIR=`echo $SERVICE_CONTENT_DIRECTORY | sed -e "s/$SERVICE_SRV_NAME//"`
HORIZON_CONFIGS="/opt/stack/horizon/openstack_dashboard/settings.py,/usr/share/openstack-dashboard/openstack_dashboard/settings.py"
APACHE_USER=apache
APACHE_GROUP=apache
LOG_DIR="/var/log/murano/"
# Functions
# Loger function
@ -42,7 +43,7 @@ in_sys_pkg()
PKG=$1
rpm -q $PKG > /dev/null 2>&1
if [ $? -eq 0 ]; then
log "Package \"$PKG\" already installed"
log "Package \"$PKG\" already installed"
else
log "Installing \"$PKG\"..."
yum install $PKG --assumeyes > /dev/null 2>&1
@ -56,19 +57,19 @@ in_sys_pkg()
# find pip
find_pip()
{
for cmd in $PIPAPPS
do
_cmd=$(which $cmd 2>/dev/null)
if [ $? -eq 0 ];then
break
fi
done
if [ -z $_cmd ];then
echo "Can't find \"pip\" in system, please install it first, exiting!"
exit 1
else
PIPCMD=$_cmd
fi
for cmd in $PIPAPPS
do
_cmd=$(which $cmd 2>/dev/null)
if [ $? -eq 0 ];then
break
fi
done
if [ -z $_cmd ];then
echo "Can't find \"pip\" in system, please install it first, exiting!"
exit 1
else
PIPCMD=$_cmd
fi
}
# git clone
@ -79,8 +80,8 @@ gitclone()
log "Cloning from \"$FROM\" repo to \"$CLONEROOT\""
cd $CLONEROOT && git clone $FROM > /dev/null 2>&1
if [ $? -ne 0 ];then
log "cloning from \"$FROM\" fails, exiting!!!"
exit
log "cloning from \"$FROM\" fails, exiting!!!"
exit
fi
}
@ -94,16 +95,16 @@ modify_horizon_config() {
log "Removing our data from \"$1\"..."
sed -e '/^#START_MURANO_DASHBOARD/,/^#END_MURANO_DASHBOARD/ d' -i $1
if [ $? -ne 0 ];then
log "Can't modify \"$1\", check permissions or something else, exiting!!!"
log "Can't modify \"$1\", check permissions or something else, exiting!!!"
exit
fi
fi
else
log "\"$1\" already has our data, you can change it manualy and restart apache2 service"
fi
else
if [ -z $REMOVE ];then
log "Adding our data into \"$1\"..."
cat >> $1 << "EOF"
cat >> $1 << EOF
#START_MURANO_DASHBOARD
HORIZON_CONFIG['dashboards'] += ('murano',)
INSTALLED_APPS += ('muranodashboard','floppyforms',)
@ -111,9 +112,11 @@ MIDDLEWARE_CLASSES += ('muranodashboard.middleware.ExceptionMiddleware',)
verbose_formatter = {'verbose': {'format': '[%(asctime)s] [%(levelname)s] [pid=%(process)d] %(message)s'}}
if 'formatters' in LOGGING: LOGGING['formatters'].update(verbose_formatter)
else: LOGGING['formatters'] = verbose_formatter
LOGGING['handlers']['murano-file'] = {'level': 'DEBUG', 'formatter': 'verbose', 'class': 'logging.FileHandler', 'filename': '/var/log/murano-dashboard.log'}
LOGGING['handlers']['murano-file'] = {'level': 'DEBUG', 'formatter': 'verbose', 'class': 'logging.FileHandler', 'filename': '$LOG_DIR/murano-dashboard.log'}
LOGGING['loggers']['muranodashboard'] = {'handlers': ['murano-file'], 'level': 'DEBUG'}
LOGGING['loggers']['muranoclient'] = {'handlers': ['murano-file'], 'level': 'ERROR'}
#MURANO_API_URL = "http://localhost:8082"
#MURANO_METADATA_URL = "http://localhost:8084"
#if murano-api set up with ssl uncomment next strings
#MURANO_API_INSECURE = True
#END_MURANO_DASHBOARD
@ -151,44 +154,45 @@ find_horizon_config()
preinst()
{
# check openstack-dashboard installed from system packages
_PKG=openstack-dashboard
rpm -q $_PKG > /dev/null 2>&1
if [ $? -ne 0 ]; then
log "Package \"$_PKG\" is not installed."
fi
_PKG=openstack-dashboard
rpm -q $_PKG > /dev/null 2>&1
if [ $? -ne 0 ]; then
log "Package \"$_PKG\" is not installed."
fi
}
# rebuild static
rebuildstatic()
{
horizon_manage=$(rpm -ql openstack-dashboard | grep -E "*manage.py$")
if [ $? -ne 0 ]; then
log "openstack-dashboard manage.py not found, exiting!!!"
exit 1
fi
_old_murano_static="$(dirname $horizon_manage)/openstack_dashboard/static/muranodashboard"
if [ -d "$_old_murano_static" ];then
log "Our staic for \"muranodashboard\" found under \"HORIZON\" STATIC, deleting \"$_old_murano_static\"..."
rm -rf $_old_murano_static
if [ $? -ne 0 ]; then
log "Can't delete \"$_old_murano_static\, WARNING!!!"
fi
fi
log "Rebuilding STATIC...."
python $horizon_manage collectstatic --noinput
if [ $? -ne 0 ]; then
log "\"$horizon_manage\" collectstatic failed, exiting!!!"
exit 1
fi
horizon_manage=$(rpm -ql openstack-dashboard | grep -E "*manage.py$")
if [ $? -ne 0 ]; then
log "openstack-dashboard manage.py not found, exiting!!!"
exit 1
fi
_old_murano_static="$(dirname $horizon_manage)/openstack_dashboard/static/muranodashboard"
if [ -d "$_old_murano_static" ];then
log "Our static for \"muranodashboard\" found under \"HORIZON\" STATIC, deleting \"$_old_murano_static\"..."
rm -rf $_old_murano_static
if [ $? -ne 0 ]; then
log "Can't delete \"$_old_murano_static\, WARNING!!!"
fi
fi
log "Rebuilding STATIC...."
python $horizon_manage collectstatic --noinput
if [ $? -ne 0 ]; then
log "\"$horizon_manage\" collectstatic failed, exiting!!!"
exit 1
fi
}
# postinstall
postinst()
{
rebuildstatic
sleep 2
chown apache:apache /var/log/murano-dashboard.log
service httpd restart
rebuildstatic
sleep 2
chown $APACHE_USER:$APACHE_GROUP $LOG_DIR/murano-dashboard.log
chown -R $APACHE_USER:$APACHE_GROUP /var/lib/openstack-dashboard
service httpd restart
}
@ -225,28 +229,38 @@ CLONE_FROM_GIT=$1
MRN_CND_SPY=$SERVICE_CONTENT_DIRECTORY/setup.py
if [ -e $MRN_CND_SPY ]; then
chmod +x $MRN_CND_SPY
log "$MRN_CND_SPY output:_____________________________________________________________"
log "$MRN_CND_SPY output:_____________________________________________________________"
## Setup through pip
# Creating tarball
rm -rf $SERVICE_CONTENT_DIRECTORY/*.egg-info
cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY egg_info
if [ $? -ne 0 ];then
log "\"$MRN_CND_SPY\" egg info creation FAILS, exiting!!!"
exit 1
fi
rm -rf $SERVICE_CONTENT_DIRECTORY/dist
if [ $? -ne 0 ];then
log "\"$MRN_CND_SPY\" egg info creation FAILS, exiting!!!"
exit 1
fi
rm -rf $SERVICE_CONTENT_DIRECTORY/dist
cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY sdist
if [ $? -ne 0 ];then
log "\"$MRN_CND_SPY\" tarball creation FAILS, exiting!!!"
exit 1
fi
# Running tarball install
# Running tarball install
TRBL_FILE=$(basename `ls $SERVICE_CONTENT_DIRECTORY/dist/*.tar.gz`)
$PIPCMD install $SERVICE_CONTENT_DIRECTORY/dist/$TRBL_FILE
if [ $? -ne 0 ];then
log "$PIPCMD install \"$TRBL_FILE\" FAILS, exiting!!!"
exit 1
fi
# Creating log directory for the murano
if [ ! -d $LOG_DIR ];then
log "Creating $LOG_DIR direcory..."
mkdir -p $LOG_DIR
if [ $? -ne 0 ];then
log "Can't create $LOG_DIR, exiting!!!"
exit 1
fi
chmod -R a+rw $LOG_DIR
fi
else
log "$MRN_CND_SPY not found!"
fi
@ -258,9 +272,9 @@ CLONE_FROM_GIT=$1
# uninstall
uninst()
{
# Uninstall trough pip
# Uninstall trough pip
find_pip
# looking up for python package installed
# looking up for python package installed
PYPKG=`echo $SERVICE_SRV_NAME | tr -d '-'`
_pkg=$($PIPCMD freeze | grep $PYPKG)
if [ $? -eq 0 ]; then
@ -278,10 +292,10 @@ case $COMMAND in
postinst
;;
testuninstall )
find_horizon_config remove
testuninstall )
find_horizon_config remove
postinst
;;
;;
install )
inst

View File

@ -23,6 +23,7 @@ GIT_CLONE_DIR=`echo $SERVICE_CONTENT_DIRECTORY | sed -e "s/$SERVICE_SRV_NAME//"`
HORIZON_CONFIGS="/opt/stack/horizon/openstack_dashboard/settings.py,/usr/share/openstack-dashboard/openstack_dashboard/settings.py"
APACHE_USER=www-data
APACHE_GROUP=www-data
LOG_DIR="/var/log/murano/"
# Functions
# Logger function
@ -74,16 +75,16 @@ modify_horizon_config() {
log "Removing our data from \"$1\"..."
sed -e '/^#START_MURANO_DASHBOARD/,/^#END_MURANO_DASHBOARD/ d' -i $1
if [ $? -ne 0 ];then
log "Can't modify \"$1\", check permissions or something else, exiting!!!"
log "Can't modify \"$1\", check permissions or something else, exiting!!!"
exit
fi
fi
else
log "\"$1\" already has our data, you can change it manually and restart apache2 service"
fi
else
if [ -z $REMOVE ];then
log "Adding our data into \"$1\"..."
cat >> $1 << "EOF"
cat >> $1 << EOF
#START_MURANO_DASHBOARD
HORIZON_CONFIG['dashboards'] += ('murano',)
INSTALLED_APPS += ('muranodashboard','floppyforms',)
@ -91,9 +92,11 @@ MIDDLEWARE_CLASSES += ('muranodashboard.middleware.ExceptionMiddleware',)
verbose_formatter = {'verbose': {'format': '[%(asctime)s] [%(levelname)s] [pid=%(process)d] %(message)s'}}
if 'formatters' in LOGGING: LOGGING['formatters'].update(verbose_formatter)
else: LOGGING['formatters'] = verbose_formatter
LOGGING['handlers']['murano-file'] = {'level': 'DEBUG', 'formatter': 'verbose', 'class': 'logging.FileHandler', 'filename': '/var/log/murano-dashboard.log'}
LOGGING['handlers']['murano-file'] = {'level': 'DEBUG', 'formatter': 'verbose', 'class': 'logging.FileHandler', 'filename': '$LOG_DIR/murano-dashboard.log'}
LOGGING['loggers']['muranodashboard'] = {'handlers': ['murano-file'], 'level': 'DEBUG'}
LOGGING['loggers']['muranoclient'] = {'handlers': ['murano-file'], 'level': 'ERROR'}
#MURANO_API_URL = "http://localhost:8082"
#MURANO_METADATA_URL = "http://localhost:8084"
#if murano-api set up with ssl uncomment next strings
#MURANO_API_INSECURE = True
#END_MURANO_DASHBOARD
@ -160,28 +163,38 @@ CLONE_FROM_GIT=$1
MRN_CND_SPY=$SERVICE_CONTENT_DIRECTORY/setup.py
if [ -e $MRN_CND_SPY ]; then
chmod +x $MRN_CND_SPY
log "$MRN_CND_SPY output:_____________________________________________________________"
log "$MRN_CND_SPY output:_____________________________________________________________"
## Setup through pip
# Creating tarball
rm -rf $SERVICE_CONTENT_DIRECTORY/*.egg-info
cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY egg_info
if [ $? -ne 0 ];then
log "\"$MRN_CND_SPY\" egg info creation FAILS, exiting!!!"
exit 1
fi
rm -rf $SERVICE_CONTENT_DIRECTORY/dist
if [ $? -ne 0 ];then
log "\"$MRN_CND_SPY\" egg info creation FAILS, exiting!!!"
exit 1
fi
rm -rf $SERVICE_CONTENT_DIRECTORY/dist
cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY sdist
if [ $? -ne 0 ];then
log "\"$MRN_CND_SPY\" tarball creation FAILS, exiting!!!"
exit 1
fi
# Running tarball install
# Running tarball install
TRBL_FILE=$(basename `ls $SERVICE_CONTENT_DIRECTORY/dist/*.tar.gz`)
pip install $SERVICE_CONTENT_DIRECTORY/dist/$TRBL_FILE
if [ $? -ne 0 ];then
log "pip install \"$TRBL_FILE\" FAILS, exiting!!!"
exit 1
fi
# Creating log directory for the murano
if [ ! -d $LOG_DIR ];then
log "Creating $LOG_DIR direcory..."
mkdir -p $LOG_DIR
if [ $? -ne 0 ];then
log "Can't create $LOG_DIR, exiting!!!"
exit 1
fi
chmod -R a+rw $LOG_DIR
fi
else
log "$MRN_CND_SPY not found!"
fi
@ -190,8 +203,8 @@ CLONE_FROM_GIT=$1
# uninstall
uninst()
{
# Uninstall trough pip
# looking up for python package installed
# Uninstall trough pip
# looking up for python package installed
PYPKG=`echo $SERVICE_SRV_NAME | tr -d '-'`
pip freeze | grep $PYPKG
if [ $? -eq 0 ]; then
@ -207,41 +220,42 @@ preinst()
# check openstack-dashboard installed from system packages
_PKG=openstack-dashboard
dpkg -s $_PKG > /dev/null 2>&1
if [ $? -ne 0 ]; then
log "Package \"$_PKG\" is not installed."
if [ $? -ne 0 ]; then
log "Package \"$_PKG\" is not installed."
fi
}
# rebuild static
rebuildstatic()
{
horizon_manage=$(dpkg-query -L openstack-dashboard | grep -E "*manage.py$")
if [ $? -ne 0 ]; then
log "openstack-dashboard manage.py not found, exiting!!!"
exit 1
fi
_old_murano_static="$(dirname $horizon_manage)/openstack_dashboard/static/muranodashboard"
if [ -d "$_old_murano_static" ];then
log "Our staic for \"muranodashboard\" found under \"HORIZON\" STATIC, deleting \"$_old_murano_static\"..."
rm -rf $_old_murano_static
if [ $? -ne 0 ]; then
log "Can't delete \"$_old_murano_static\, WARNING!!!"
fi
fi
log "Rebuilding STATIC...."
python $horizon_manage collectstatic --noinput
if [ $? -ne 0 ]; then
log "\"$horizon_manage\" collectstatic failed, exiting!!!"
exit 1
fi
horizon_manage=$(dpkg-query -L openstack-dashboard | grep -E "*manage.py$")
if [ $? -ne 0 ]; then
log "openstack-dashboard manage.py not found, exiting!!!"
exit 1
fi
_old_murano_static="$(dirname $horizon_manage)/openstack_dashboard/static/muranodashboard"
if [ -d "$_old_murano_static" ];then
log "Our static for \"muranodashboard\" found under \"HORIZON\" STATIC, deleting \"$_old_murano_static\"..."
rm -rf $_old_murano_static
if [ $? -ne 0 ]; then
log "Can't delete \"$_old_murano_static\, WARNING!!!"
fi
fi
log "Rebuilding STATIC...."
python $horizon_manage collectstatic --noinput
if [ $? -ne 0 ]; then
log "\"$horizon_manage\" collectstatic failed, exiting!!!"
exit 1
fi
}
# postinstall
postinst()
{
rebuildstatic
rebuildstatic
sleep 2
chown $APACHE_USER:$APACHE_GROUP /var/log/murano-dashboard.log
chown $APACHE_USER:$APACHE_GROUP $LOG_DIR/murano-dashboard.log
chown -R horizon:horizon /var/lib/openstack-dashboard
service apache2 restart
}
# Command line args'