Add common log and configuration places

Change-Id: I2de692931fbc3de923489eb943ecc233d1366730
This commit is contained in:
Igor Yozhikov 2013-11-27 15:09:10 +04:00
parent 84600e4a1c
commit a1173478ce
2 changed files with 104 additions and 72 deletions

View File

@ -22,7 +22,9 @@ PIPAPPS="pip python-pip pip-python"
PIPCMD="" PIPCMD=""
SERVICE_SRV_NAME="murano-conductor" SERVICE_SRV_NAME="murano-conductor"
GIT_CLONE_DIR=`echo $SERVICE_CONTENT_DIRECTORY | sed -e "s/$SERVICE_SRV_NAME//"` 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/conductor.conf" SERVICE_CONFIG_FILE_PATH="$ETC_CFG_DIR/conductor.conf"
# Functions # Functions
@ -41,13 +43,13 @@ in_sys_pkg()
PKG=$1 PKG=$1
rpm -q $PKG > /dev/null 2>&1 rpm -q $PKG > /dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
log "Package \"$PKG\" already installed" log "Package \"$PKG\" already installed"
else else
log "Installing \"$PKG\"..." log "Installing \"$PKG\"..."
yum install $PKG --assumeyes > /dev/null 2>&1 yum install $PKG --assumeyes > /dev/null 2>&1
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
log "installation fails, exiting!!!" log "installation fails, exiting!!!"
exit exit
fi fi
fi fi
} }
@ -55,19 +57,19 @@ in_sys_pkg()
# find pip # find pip
find_pip() find_pip()
{ {
for cmd in $PIPAPPS for cmd in $PIPAPPS
do do
_cmd=$(which $cmd 2>/dev/null) _cmd=$(which $cmd 2>/dev/null)
if [ $? -eq 0 ];then if [ $? -eq 0 ];then
break break
fi fi
done done
if [ -z $_cmd ];then if [ -z $_cmd ];then
echo "Can't find \"pip\" in system, please install it first, exiting!" echo "Can't find \"pip\" in system, please install it first, exiting!"
exit 1 exit 1
else else
PIPCMD=$_cmd PIPCMD=$_cmd
fi fi
} }
# git clone # git clone
@ -77,10 +79,10 @@ gitclone()
CLONEROOT=$2 CLONEROOT=$2
log "Cloning from \"$FROM\" repo to \"$CLONEROOT\"" log "Cloning from \"$FROM\" repo to \"$CLONEROOT\""
cd $CLONEROOT && git clone $FROM > /dev/null 2>&1 cd $CLONEROOT && git clone $FROM > /dev/null 2>&1
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
log "cloning from \"$FROM\" fails, exiting!!!" log "cloning from \"$FROM\" fails, exiting!!!"
exit exit
fi fi
} }
# install # install
@ -90,41 +92,41 @@ CLONE_FROM_GIT=$1
# Checking packages # Checking packages
for PKG in $PREREQ_PKGS for PKG in $PREREQ_PKGS
do do
in_sys_pkg $PKG in_sys_pkg $PKG
done done
# Find python pip # Find python pip
find_pip find_pip
# If clone from git set # If clone from git set
if [ ! -z $CLONE_FROM_GIT ]; then if [ ! -z $CLONE_FROM_GIT ]; then
# Preparing clone root directory # Preparing clone root directory
if [ ! -d $GIT_CLONE_DIR ];then if [ ! -d $GIT_CLONE_DIR ];then
log "Creating $GIT_CLONE_DIR direcory..." log "Creating $GIT_CLONE_DIR direcory..."
mkdir -p $GIT_CLONE_DIR mkdir -p $GIT_CLONE_DIR
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
log "Can't create $GIT_CLONE_DIR, exiting!!!" log "Can't create $GIT_CLONE_DIR, exiting!!!"
exit exit
fi
fi fi
fi
# Cloning from GIT # Cloning from GIT
GIT_WEBPATH_PRFX="https://github.com/stackforge/" GIT_WEBPATH_PRFX="https://github.com/stackforge/"
gitclone "$GIT_WEBPATH_PRFX$SERVICE_SRV_NAME.git" $GIT_CLONE_DIR gitclone "$GIT_WEBPATH_PRFX$SERVICE_SRV_NAME.git" $GIT_CLONE_DIR
# End clone from git section # End clone from git section
fi fi
# Setupping... # Setupping...
log "Running setup.py" log "Running setup.py"
MRN_CND_SPY=$GIT_CLONE_DIR/$SERVICE_SRV_NAME/setup.py MRN_CND_SPY=$GIT_CLONE_DIR/$SERVICE_SRV_NAME/setup.py
if [ -e $MRN_CND_SPY ];then if [ -e $MRN_CND_SPY ];then
chmod +x $MRN_CND_SPY chmod +x $MRN_CND_SPY
log "$MRN_CND_SPY output:_____________________________________________________________" log "$MRN_CND_SPY output:_____________________________________________________________"
## Setup through pip ## Setup through pip
# Creating tarball # Creating tarball
rm -rf $SERVICE_CONTENT_DIRECTORY/*.egg-info rm -rf $SERVICE_CONTENT_DIRECTORY/*.egg-info
cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY egg_info cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY egg_info
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
log "\"$MRN_CND_SPY\" egg info creation FAILS, exiting!!!" log "\"$MRN_CND_SPY\" egg info creation FAILS, exiting!!!"
exit 1 exit 1
fi fi
rm -rf $SERVICE_CONTENT_DIRECTORY/dist/* rm -rf $SERVICE_CONTENT_DIRECTORY/dist/*
cd $SERVICE_CONTENT_DIRECTORY && $MRN_CND_SPY sdist cd $SERVICE_CONTENT_DIRECTORY && $MRN_CND_SPY sdist
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
@ -150,15 +152,29 @@ CLONE_FROM_GIT=$1
exit exit
fi fi
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 # making sample 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) for file in $(ls $SERVICE_CONTENT_DIRECTORY/etc)
do do
cp -f "$SERVICE_CONTENT_DIRECTORY/etc/$file" "$ETC_CFG_DIR/$file.sample" if [ -d "$SERVICE_CONTENT_DIRECTORY/etc/$file" ];then
cp -f -R "$SERVICE_CONTENT_DIRECTORY/etc/$file" "$ETC_CFG_DIR/"
else
cp -f "$SERVICE_CONTENT_DIRECTORY/etc/$file" "$ETC_CFG_DIR/$file.sample"
fi
done done
# making templates data # making templates data
log "Making templates directory" #log "Making templates directory"
cp -f -R "$SERVICE_CONTENT_DIRECTORY/data" "$ETC_CFG_DIR/" #cp -f -R "$SERVICE_CONTENT_DIRECTORY/data" "$ETC_CFG_DIR/"
} }
# searching for service executable in path # searching for service executable in path
@ -187,24 +203,24 @@ start on runlevel [2345]
stop on runlevel [!2345] stop on runlevel [!2345]
respawn respawn
exec $SERVICE_EXEC_PATH --config-file=$SERVICE_CONFIG_FILE_PATH" > "/etc/init/$SERVICE_SRV_NAME.conf" exec $SERVICE_EXEC_PATH --config-file=$SERVICE_CONFIG_FILE_PATH" > "/etc/init/$SERVICE_SRV_NAME.conf"
log "Reloading initctl" log "Reloading initctl"
initctl reload-configuration initctl reload-configuration
} }
# purge init # purge init
purgeinit() purgeinit()
{ {
rm -f /etc/init/$SERVICE_SRV_NAME.conf rm -f /etc/init/$SERVICE_SRV_NAME.conf
log "Reloading initctl" log "Reloading initctl"
initctl reload-configuration initctl reload-configuration
} }
# uninstall # uninstall
uninst() uninst()
{ {
# Uninstall trough pip # Uninstall trough pip
find_pip find_pip
# looking up for python package installed # looking up for python package installed
PYPKG=$SERVICE_SRV_NAME PYPKG=$SERVICE_SRV_NAME
_pkg=$($PIPCMD freeze | grep $PYPKG) _pkg=$($PIPCMD freeze | grep $PYPKG)
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
@ -224,10 +240,10 @@ postinst()
COMMAND="$1" COMMAND="$1"
case $COMMAND in case $COMMAND in
inject-init ) inject-init )
get_service_exec_path get_service_exec_path
log "Injecting \"$SERVICE_SRV_NAME\" to init..." log "Injecting \"$SERVICE_SRV_NAME\" to init..."
injectinit injectinit
postinst postinst
;; ;;
install ) install )

View File

@ -20,7 +20,9 @@ SERVICE_CONTENT_DIRECTORY=`cd $(dirname "$0") && pwd`
PREREQ_PKGS="upstart wget git make python-pip python-dev python-mysqldb libxml2-dev libxslt-dev libffi-dev" PREREQ_PKGS="upstart wget git make python-pip python-dev python-mysqldb libxml2-dev libxslt-dev libffi-dev"
SERVICE_SRV_NAME="murano-conductor" SERVICE_SRV_NAME="murano-conductor"
GIT_CLONE_DIR=`echo $SERVICE_CONTENT_DIRECTORY | sed -e "s/$SERVICE_SRV_NAME//"` 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/conductor.conf" SERVICE_CONFIG_FILE_PATH="$ETC_CFG_DIR/conductor.conf"
# Functions # Functions
@ -39,12 +41,12 @@ in_sys_pkg()
PKG=$1 PKG=$1
dpkg -s $PKG > /dev/null 2>&1 dpkg -s $PKG > /dev/null 2>&1
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
log "Package \"$PKG\" already installed" log "Package \"$PKG\" already installed"
else else
log "Installing \"$PKG\"..." log "Installing \"$PKG\"..."
apt-get install $PKG --yes > /dev/null 2>&1 apt-get install $PKG --yes > /dev/null 2>&1
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
log "installation fails, exiting!!!" log "installation fails, exiting!!!"
exit exit
fi fi
fi fi
@ -58,15 +60,15 @@ gitclone()
log "Cloning from \"$FROM\" repo to \"$CLONEROOT\"" log "Cloning from \"$FROM\" repo to \"$CLONEROOT\""
cd $CLONEROOT && git clone $FROM > /dev/null 2>&1 cd $CLONEROOT && git clone $FROM > /dev/null 2>&1
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
log "cloning from \"$FROM\" fails, exiting!!!" log "cloning from \"$FROM\" fails, exiting!!!"
exit exit
fi fi
} }
# install # install
inst() inst()
{ {
CLONE_FROM_GIT=$1 CLONE_FROM_GIT=$1
# Checking packages # Checking packages
for PKG in $PREREQ_PKGS for PKG in $PREREQ_PKGS
do do
@ -81,8 +83,8 @@ CLONE_FROM_GIT=$1
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
log "Can't create $GIT_CLONE_DIR, exiting!!!" log "Can't create $GIT_CLONE_DIR, exiting!!!"
exit exit
fi fi
fi fi
# Cloning from GIT # Cloning from GIT
GIT_WEBPATH_PRFX="https://github.com/stackforge/" GIT_WEBPATH_PRFX="https://github.com/stackforge/"
gitclone "$GIT_WEBPATH_PRFX$SERVICE_SRV_NAME.git" $GIT_CLONE_DIR gitclone "$GIT_WEBPATH_PRFX$SERVICE_SRV_NAME.git" $GIT_CLONE_DIR
@ -94,15 +96,15 @@ CLONE_FROM_GIT=$1
MRN_CND_SPY=$SERVICE_CONTENT_DIRECTORY/setup.py MRN_CND_SPY=$SERVICE_CONTENT_DIRECTORY/setup.py
if [ -e $MRN_CND_SPY ];then if [ -e $MRN_CND_SPY ];then
chmod +x $MRN_CND_SPY chmod +x $MRN_CND_SPY
log "$MRN_CND_SPY output:_____________________________________________________________" log "$MRN_CND_SPY output:_____________________________________________________________"
## Setup through pip ## Setup through pip
# Creating tarball # Creating tarball
rm -rf $SERVICE_CONTENT_DIRECTORY/*.egg-info rm -rf $SERVICE_CONTENT_DIRECTORY/*.egg-info
cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY egg_info cd $SERVICE_CONTENT_DIRECTORY && python $MRN_CND_SPY egg_info
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
log "\"$MRN_CND_SPY\" egg info creation FAILS, exiting!!!" log "\"$MRN_CND_SPY\" egg info creation FAILS, exiting!!!"
exit 1 exit 1
fi fi
rm -rf $SERVICE_CONTENT_DIRECTORY/dist/* rm -rf $SERVICE_CONTENT_DIRECTORY/dist/*
cd $SERVICE_CONTENT_DIRECTORY && $MRN_CND_SPY sdist cd $SERVICE_CONTENT_DIRECTORY && $MRN_CND_SPY sdist
if [ $? -ne 0 ];then if [ $? -ne 0 ];then
@ -128,15 +130,29 @@ CLONE_FROM_GIT=$1
exit 1 exit 1
fi fi
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 # making sample 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) for file in $(ls $SERVICE_CONTENT_DIRECTORY/etc)
do do
cp -f "$SERVICE_CONTENT_DIRECTORY/etc/$file" "$ETC_CFG_DIR/$file.sample" if [ -d "$SERVICE_CONTENT_DIRECTORY/etc/$file" ];then
cp -f -R "$SERVICE_CONTENT_DIRECTORY/etc/$file" "$ETC_CFG_DIR/"
else
cp -f "$SERVICE_CONTENT_DIRECTORY/etc/$file" "$ETC_CFG_DIR/$file.sample"
fi
done done
# making templates data # making templates data
log "Making templates directory" #log "Making templates directory"
cp -f -R "$SERVICE_CONTENT_DIRECTORY/data" "$ETC_CFG_DIR/" #cp -f -R "$SERVICE_CONTENT_DIRECTORY/data" "$ETC_CFG_DIR/"
} }
# searching for service executable in path # searching for service executable in path
@ -170,8 +186,8 @@ start on runlevel [2345]
stop on runlevel [!2345] stop on runlevel [!2345]
respawn 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" 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" log "Reloading initctl"
initctl reload-configuration initctl reload-configuration
} }
# purge init # purge init
@ -186,8 +202,8 @@ purgeinit()
# uninstall # uninstall
uninst() uninst()
{ {
# Uninstall trough pip # Uninstall trough pip
# looking up for python package installed # looking up for python package installed
PYPKG=$SERVICE_SRV_NAME PYPKG=$SERVICE_SRV_NAME
pip freeze | grep $PYPKG pip freeze | grep $PYPKG
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then