Add common log and configuration places

Change-Id: I09df89b4d5e004a69099dad33158f1b7521605aa
This commit is contained in:
Igor Yozhikov 2013-11-27 15:06:07 +04:00
parent 4c9c97b79b
commit a43044d2c2
2 changed files with 82 additions and 70 deletions

View File

@ -22,7 +22,9 @@ PIPAPPS="pip python-pip pip-python"
PIPCMD=""
SERVICE_SRV_NAME="murano-api"
GIT_CLONE_DIR=`echo $SERVICE_CONTENT_DIRECTORY | sed -e "s/$SERVICE_SRV_NAME//"`
ETC_CFG_DIR="/etc/$SERVICE_SRV_NAME"
#ETC_CFG_DIR="/etc/$SERVICE_SRV_NAME"
ETC_CFG_DIR="/etc/murano"
LOG_DIR="/var/log/murano/"
SERVICE_CONFIG_FILE_PATH="$ETC_CFG_DIR/murano-api.conf"
# Functions
@ -41,13 +43,13 @@ 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
if [ $? -ne 0 ];then
log "installation fails, exiting!!!"
exit 1
log "Installing \"$PKG\"..."
yum install $PKG --assumeyes > /dev/null 2>&1
if [ $? -ne 0 ];then
log "installation fails, exiting!!!"
exit 1
fi
fi
}
@ -55,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
@ -78,9 +80,9 @@ 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
fi
log "cloning from \"$FROM\" fails, exiting!!!"
exit
fi
}
# install
@ -121,10 +123,10 @@ CLONE_FROM_GIT=$1
# 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
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 && $MRN_CND_SPY sdist
if [ $? -ne 0 ];then
@ -143,15 +145,25 @@ CLONE_FROM_GIT=$1
fi
# Creating etc directory for config files
if [ ! -d $ETC_CFG_DIR ]; then
log "Creting $ETC_CFG_DIR direcory..."
mkdir -p $ETC_CFG_DIR
if [ $? -ne 0 ]; then
log "Can't create $ETC_CFG_DIR, exiting!!!"
exit
fi
fi
log "Creting $ETC_CFG_DIR direcory..."
mkdir -p $ETC_CFG_DIR
if [ $? -ne 0 ]; then
log "Can't create $ETC_CFG_DIR, exiting!!!"
exit
fi
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
# making smaple configs
log "Making sample configuration files at \"$ETC_CFG_DIR\""
log "Making sample configuration files at \"$ETC_CFG_DIR\""
for file in `ls $SERVICE_CONTENT_DIRECTORY/etc`
do
cp -f "$SERVICE_CONTENT_DIRECTORY/etc/$file" "$ETC_CFG_DIR/$file.sample"
@ -184,24 +196,24 @@ start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec $SERVICE_EXEC_PATH --config-file=$SERVICE_CONFIG_FILE_PATH" > "/etc/init/$SERVICE_SRV_NAME.conf"
log "Reloading initctl"
initctl reload-configuration
log "Reloading initctl"
initctl reload-configuration
}
# purge init
purgeinit()
{
rm -f /etc/init/$SERVICE_SRV_NAME.conf
log "Reloading initctl"
initctl reload-configuration
rm -f /etc/init/$SERVICE_SRV_NAME.conf
log "Reloading initctl"
initctl reload-configuration
}
# uninstall
uninst()
{
# Uninstall trough pip
find_pip
# looking up for python package installed
# Uninstall trough pip
find_pip
# looking up for python package installed
PYPKG=`echo $SERVICE_SRV_NAME | tr -d '-'`
_pkg=$($PIPCMD freeze | grep $PYPKG)
if [ $? -eq 0 ]; then

View File

@ -20,7 +20,9 @@ SERVICE_CONTENT_DIRECTORY=`cd $(dirname "$0") && pwd`
PREREQ_PKGS="wget make git python-pip python-dev python-mysqldb libxml2-dev libxslt-dev libffi-dev"
SERVICE_SRV_NAME="murano-api"
GIT_CLONE_DIR=`echo $SERVICE_CONTENT_DIRECTORY | sed -e "s/$SERVICE_SRV_NAME//"`
ETC_CFG_DIR="/etc/$SERVICE_SRV_NAME"
#ETC_CFG_DIR="/etc/$SERVICE_SRV_NAME"
ETC_CFG_DIR="/etc/murano"
LOG_DIR="/var/log/murano/"
SERVICE_CONFIG_FILE_PATH="$ETC_CFG_DIR/murano-api.conf"
# Functions
@ -39,7 +41,7 @@ in_sys_pkg()
PKG=$1
dpkg -s $PKG > /dev/null 2>&1
if [ $? -eq 0 ]; then
log "Package \"$PKG\" already installed"
log "Package \"$PKG\" already installed"
else
log "Installing \"$PKG\"..."
apt-get install $PKG --yes > /dev/null 2>&1
@ -58,8 +60,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
}
@ -71,7 +73,7 @@ CLONE_FROM_GIT=$1
for PKG in $PREREQ_PKGS
do
in_sys_pkg $PKG
done
done
# If clone from git set
if [ ! -z $CLONE_FROM_GIT ]; then
@ -89,28 +91,20 @@ CLONE_FROM_GIT=$1
gitclone "$GIT_WEBPATH_PRFX$SERVICE_SRV_NAME.git" $GIT_CLONE_DIR
# End clone from git section
fi
# Setupping...
log "Running setup.py"
#MRN_CND_SPY=$GIT_CLONE_DIR/$SERVICE_SRV_NAME/setup.py
MRN_CND_SPY=$SERVICE_CONTENT_DIRECTORY/setup.py
if [ -e $MRN_CND_SPY ]; then
chmod +x $MRN_CND_SPY
log "$MRN_CND_SPY output:_____________________________________________________________"
#cd $GIT_CLONE_DIR/$SERVICE_SRV_NAME && $MRN_CND_SPY install
#if [ $? -ne 0 ]; then
# log "\"$MRN_CND_SPY\" python setup FAILS, exiting!"
# exit 1
#fi
## Setup through pip
# Creating tarball
#cd $GIT_CLONE_DIR/$SERVICE_SRV_NAME && $MRN_CND_SPY sdist
rm -rf $SERVICE_CONTENT_DIRECTORY/*.egg-info
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
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 && $MRN_CND_SPY sdist
if [ $? -ne 0 ];then
@ -118,8 +112,6 @@ CLONE_FROM_GIT=$1
exit 1
fi
# Running tarball install
#TRBL_FILE=$(basename `ls $GIT_CLONE_DIR/$SERVICE_SRV_NAME/dist/*.tar.gz`)
#pip install $GIT_CLONE_DIR/$SERVICE_SRV_NAME/dist/$TRBL_FILE
TRBL_FILE=$(basename `ls $SERVICE_CONTENT_DIRECTORY/dist/*.tar.gz`)
pip install $SERVICE_CONTENT_DIRECTORY/dist/$TRBL_FILE
if [ $? -ne 0 ];then
@ -138,12 +130,20 @@ CLONE_FROM_GIT=$1
exit 1
fi
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
# making sample configs
log "Making sample configuration files at \"$ETC_CFG_DIR\""
#for file in `ls $GIT_CLONE_DIR/$SERVICE_SRV_NAME/etc`
for file in `ls $SERVICE_CONTENT_DIRECTORY/etc`
for file in $(ls $SERVICE_CONTENT_DIRECTORY/etc)
do
#cp -f "$GIT_CLONE_DIR/$SERVICE_SRV_NAME/etc/$file" "$ETC_CFG_DIR/$file.sample"
cp -f "$SERVICE_CONTENT_DIRECTORY/etc/$file" "$ETC_CFG_DIR/$file.sample"
done
}
@ -179,8 +179,8 @@ start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec start-stop-daemon --start --chuid root --user root --name $SERVICE_SRV_NAME --exec $SERVICE_EXEC_PATH -- --config-file=$SERVICE_CONFIG_FILE_PATH" > "/etc/init/$SERVICE_SRV_NAME.conf"
log "Reloading initctl"
initctl reload-configuration
log "Reloading initctl"
initctl reload-configuration
}
# purge init
@ -195,8 +195,8 @@ purgeinit()
# 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