Update for api and engine services installation

Add murano-engine SysV init scripts, updated setup.sh installer, improved mysql db setup

Change-Id: I54baaa1be9b215ff39005155d8476cea8cd042c8
This commit is contained in:
Igor Yozhikov 2014-04-04 17:35:51 +04:00
parent 54d6cbdab4
commit 6050d79162
6 changed files with 301 additions and 59 deletions

View File

@ -363,15 +363,21 @@ function mk_dir()
function get_service_exec_path()
{
retval=0
if [ -z "$1" ]; then
_daemon=$DAEMON_NAME
else
_daemon=$1
SERVICE_EXEC_PATH=''
fi
if [ -z "$SERVICE_EXEC_PATH" ]; then
SERVICE_EXEC_PATH=$(which $DAEMON_NAME)
SERVICE_EXEC_PATH=$(which $_daemon)
if [ $? -ne 0 ]; then
log "Can't find \"$DAEMON_NAME\", please install the \"$SERVICE_SRV_NAME\" by running \"$(basename "$0") install\" or set variable SERVICE_EXEC_PATH=/path/to/daemon before running setup script, exiting!"
log "Can't find \"$_daemon\", please install the \"$SERVICE_SRV_NAME\" by running \"$(basename "$0") install\" or set variable SERVICE_EXEC_PATH=/path/to/daemon before running setup script, exiting!"
retval=1
fi
else
if [ ! -x "$SERVICE_EXEC_PATH" ]; then
log "\"$SERVICE_EXEC_PATH\" in not executable, please install the \"$DAEMON_NAME\" or set variable SERVICE_EXEC_PATH=/path/to/daemon before running setup script, exiting!"
log "\"$SERVICE_EXEC_PATH\" in not executable, please install the \"$_daemon\" or set variable SERVICE_EXEC_PATH=/path/to/daemon before running setup script, exiting!"
retval=1
fi
fi

View File

@ -32,7 +32,7 @@ DAEMON=$(which murano-api)
PIDFILE=/var/run/murano/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
SYSTEM_USER=murano
CONFIG_FILE=/etc/murano/murano-api.conf
CONFIG_FILE=/etc/murano/murano.conf
# Exit if the package is not installed
[ -x $DAEMON ] || exit 5
@ -102,4 +102,3 @@ case "$1" in
exit 3
;;
esac

View File

@ -34,7 +34,7 @@ DAEMON=$(which murano-api)
PIDFILE=/var/run/murano/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
SYSTEM_USER=murano
CONFIG_FILE=/etc/murano/murano-api.conf
CONFIG_FILE=/etc/murano/murano.conf
LOCKFILE=/var/lock/subsys/$NAME
# Exit if the package is not installed
[ -x $DAEMON ] || exit 5
@ -100,4 +100,3 @@ case "$1" in
exit 2
esac
exit $?

View File

@ -0,0 +1,104 @@
#!/bin/sh
# Copyright (c) 2014 Mirantis, Inc.
#
# 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.
# Author: Igor Yozhikov <iyozhikov@mirantis.com>
#
### BEGIN INIT INFO
# Provides: murano-engine
# Required-Start: $network $local_fs $remote_fs $syslog
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OpenStack Murano Engine Server
# Description: This startup script launches murano-engine service daemon.
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
DESC="murano-engine"
NAME=murano-engine
DAEMON=$(which murano-engine)
PIDFILE=/var/run/murano/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
SYSTEM_USER=murano
CONFIG_FILE=/etc/murano/murano.conf
# Exit if the package is not installed
[ -x $DAEMON ] || exit 5
# source function library
. /lib/lsb/init-functions
do_start()
{
if [ ! -d "/var/run/murano" ]; then
mkdir -p /var/run/murano
chown -R $SYSTEM_USER /var/run/murano
fi
start-stop-daemon --start --background --quiet --chuid $SYSTEM_USER:$SYSTEM_USER --make-pidfile --pidfile $PIDFILE --startas $DAEMON --test -- --config-file=$CONFIG_FILE > /dev/null || return 1
start-stop-daemon --start --background --quiet --chuid $SYSTEM_USER:$SYSTEM_USER --make-pidfile --pidfile $PIDFILE --startas $DAEMON -- --config-file=$CONFIG_FILE || return 2
}
do_stop()
{
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
RETVAL="$?"
rm -f $PIDFILE
return "$RETVAL"
}
case "$1" in
start)
log_daemon_msg "Starting $DESC" "$NAME"
do_start
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
do_stop
case "$?" in
0|1) log_end_msg 0 ;;
2) log_end_msg 1 ;;
esac
;;
status)
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
;;
restart|force-reload)
log_daemon_msg "Restarting $DESC" "$NAME"
do_stop
case "$?" in
0|1)
do_start
case "$?" in
0) log_end_msg 0 ;;
1) log_end_msg 1 ;; # Old process is still running
*) log_end_msg 1 ;; # Failed to start
esac
;;
*)
# Failed to stop
log_end_msg 1
;;
esac
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
exit 3
;;
esac

View File

@ -0,0 +1,102 @@
#!/bin/sh
# Copyright (c) 2014 Mirantis, Inc.
#
# 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.
# Author: Igor Yozhikov <iyozhikov@mirantis.com>
#
### BEGIN INIT INFO
# Provides: murano-engine
# Required-Start: $network $local_fs $remote_fs $syslog
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OpenStack Murano Engine Server
# Description: This startup script launches murano-engine service daemon.
### END INIT INFO
# chkconfig: 3 90 10
# description: This startup script launches murano-engine service daemon.
# config: /etc/murano/murano.conf
#
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
DESC="murano-engine"
NAME=murano-engine
DAEMON=$(which murano-engine)
PIDFILE=/var/run/murano/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
SYSTEM_USER=murano
CONFIG_FILE=/etc/murano/murano.conf
LOCKFILE=/var/lock/subsys/$NAME
# Exit if the package is not installed
[ -x $DAEMON ] || exit 5
# source function library
. /etc/init.d/functions
RETVAL=0
start() {
if [ ! -d "/var/run/murano" ]; then
mkdir -p /var/run/murano
chown -R $SYSTEM_USER /var/run/murano
fi
echo -n "Starting $NAME: "
daemon --user $SYSTEM_USER "$DAEMON --config-file=$CONFIG_FILE &>/dev/null & echo \$! > $PIDFILE"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCKFILE
return $RETVAL
}
stop() {
echo -n "Stopping $NAME: "
#killproc $DAEMON -TERM
killproc -p $PIDFILE $DAEMON
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
return $RETVAL
}
restart() {
stop
start
}
rh_status() {
# run checks to determine if the service is running or use generic status
status $DAEMON
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
esac
exit $?

136
setup.sh
View File

@ -83,7 +83,7 @@ function make_tarball()
fi
rm -rf $RUN_DIR/dist/*
log "...\"setup.py sdist\" output will be recorded in \"$LOGFILE\""
cd $RUN_DIR && $setuppy sdist >> $LOGFILE 2>&1
cd $RUN_DIR && python $setuppy sdist >> $LOGFILE 2>&1
if [ $? -ne 0 ];then
log "...\"$setuppy\" tarball creation fails, exiting!!!"
retval=1
@ -126,7 +126,10 @@ function prepare_db()
_mysql_db_user="muranoUser"
_mysql_db_pass="$(genpass)"
_mysql_root_pass="swordfish"
_mysql_cmd="CREATE DATABASE IF NOT EXISTS $_mysql_db_name DEFAULT CHARACTER SET=utf8; GRANT ALL PRIVILEGES ON $_mysql_db_name.* TO '$_mysql_db_user'@'localhost' IDENTIFIED BY '$_mysql_db_pass'; GRANT ALL PRIVILEGES ON $_mysql_db_name.* TO '$_mysql_db_user'@'%' IDENTIFIED BY '$_mysql_db_pass';"
_mysql_cmd="CREATE DATABASE IF NOT EXISTS $_mysql_db_name DEFAULT CHARACTER SET=utf8; \
DROP USER '$_mysql_db_user'@'localhost'; DROP USER '$_mysql_db_user'@'%'; \
GRANT ALL PRIVILEGES ON $_mysql_db_name.* TO '$_mysql_db_user'@'localhost' IDENTIFIED BY '$_mysql_db_pass'; \
GRANT ALL PRIVILEGES ON $_mysql_db_name.* TO '$_mysql_db_user'@'%' IDENTIFIED BY '$_mysql_db_pass';"
mysql_packages="mysql-server"
case $_dist in
"debian")
@ -142,8 +145,8 @@ function prepare_db()
retval=1
break
elif [ $_ret -eq 2 ]; then
log "MySQL server already installed, so create db manually with command like this!"
log "$_mysql_cmd"
log "MySQL server already installed..."
#log "$_mysql_cmd"
break
fi
unset _ret
@ -170,23 +173,27 @@ function prepare_db()
esac
mysqladmin -u root password "$_mysql_root_pass"
if [ $? -ne 0 ]; then
log "Trying with default password..."
mysqladmin -u root -p$_mysql_root_pass password "$_mysql_root_pass"
log "Trying connect with default password..."
#mysqladmin -u root -p$_mysql_root_pass password "$_mysql_root_pass"
mysql -u root -p$_mysql_root_pass -e "status"
if [ $? -ne 0 ]; then
log "Can't set MySQL root user password, please run manually:"
log "Can't reach MySQL server with \"\$_mysql_root_pass value\" from prepare_db function root user password, please run manually:"
log "$_mysql_cmd"
log "Set connection sting to \"mysql://$_mysql_db_user:$_mysql_db_pass@localhost:3306/$_mysql_db_name\" if you plan to use MySQL, sqlite will be used by default!"
log "Set connection string to \"mysql://$_mysql_db_user:$_mysql_db_pass@localhost:3306/$_mysql_db_name\" if you plan to use MySQL, sqlite will be used by default!"
retval=1
return $retval
else
log "...success, MySQL root password reset \"\$_mysql_root_pass value\""
log "...success, MySQL reached with root password=\"\$_mysql_root_pass value\" from prepare_db function."
fi
fi
mysql -uroot -p$_mysql_root_pass -e "$_mysql_cmd"
if [ $? -ne 0 ]; then
log "DB creation fails, please run manually:"
log "$_mysql_cmd"
retval 1
retval=1
else
log "...db created"
retval=0
fi
DAEMON_DB_CONSTR="mysql://$_mysql_db_user:$_mysql_db_pass@localhost:3306/$_mysql_db_name"
return $retval
@ -195,45 +202,58 @@ function inject_init()
{
retval=0
_dist=$(lowercase $DISTRO_BASED_ON)
eval src_init_sctipt="$DAEMON_NAME-$_dist"
_initscript="$DAEMON_NAME"
cp -f "$RUN_DIR/etc/init.d/$src_init_sctipt" "/etc/init.d/$_initscript" || retval=$?
chmod +x "/etc/init.d/$_initscript" || retval=$?
iniset '' 'SYSTEM_USER' "$DAEMON_USER" "/etc/init.d/$_initscript"
iniset '' 'DAEMON' "$(shslash $SERVICE_EXEC_PATH)" "/etc/init.d/$_initscript"
iniset '' 'SCRIPTNAME' "$(shslash "/etc/init.d/$_initscript")" "/etc/init.d/$_initscript"
case $_dist in
"debian")
update-rc.d $_initscript defaults || retval=$?
update-rc.d $_initscript enable || retval=$?
;;
*)
chkconfig --add $_initscript || retval=$?
chkconfig $_initscript on || retval=$?
;;
esac
#
DAEMONS="$DAEMON_NAME murano-engine"
#
for DAEMON in $DAEMONS
do
get_service_exec_path $DAEMON || exit $?
eval src_init_sctipt="$DAEMON-$_dist"
_initscript="$DAEMON"
cp -f "$RUN_DIR/etc/init.d/$src_init_sctipt" "/etc/init.d/$_initscript" || retval=$?
chmod +x "/etc/init.d/$_initscript" || retval=$?
iniset '' 'SYSTEM_USER' "$DAEMON_USER" "/etc/init.d/$_initscript"
iniset '' 'DAEMON' "$(shslash $SERVICE_EXEC_PATH)" "/etc/init.d/$_initscript"
iniset '' 'SCRIPTNAME' "$(shslash "/etc/init.d/$_initscript")" "/etc/init.d/$_initscript"
case $_dist in
"debian")
update-rc.d $_initscript defaults || retval=$?
update-rc.d $_initscript enable || retval=$?
;;
*)
chkconfig --add $_initscript || retval=$?
chkconfig $_initscript on || retval=$?
;;
esac
done
return $retval
}
function purge_init()
{
retval=0
_dist=$(lowercase $DISTRO_BASED_ON)
_initscript="$DAEMON_NAME"
service $_initscript stop
if [ $? -ne 0 ]; then
retval=1
fi
case $_dist in
"debian")
update-rc.d $_initscript disable
update-rc.d -f $_initscript remove || retval=$?
;;
*)
chkconfig $_initscript off || retval=$?
chkconfig --del $_initscript || retval=$?
;;
esac
rm -f "/etc/init.d/$_initscript" || retval=$?
#
DAEMONS="$DAEMON_NAME murano-engine"
#
for DAEMON in $DAEMONS
do
_initscript="$DAEMON"
service $_initscript stop
if [ $? -ne 0 ]; then
retval=1
fi
case $_dist in
"debian")
update-rc.d $_initscript disable
update-rc.d -f $_initscript remove || retval=$?
;;
*)
chkconfig $_initscript off || retval=$?
chkconfig --del $_initscript || retval=$?
;;
esac
rm -f "/etc/init.d/$_initscript" || retval=$?
done
return $retval
}
function run_pip_uninstall()
@ -270,7 +290,7 @@ function install_daemon()
do
#cp -f "$_src_conf_dir/$file" "$DAEMON_CFG_DIR/$file.sample"
cp -f "$_src_conf_dir/$file" "$DAEMON_CFG_DIR/$file"
config_file=$_prefix$(echo $file | sed -e 's/.sample$//')
config_file=$(echo $file | sed -e 's/.sample$//')
#if [ ! -e "$DAEMON_CFG_DIR/$file" ]; then
if [ ! -e "$DAEMON_CFG_DIR/$config_file" ]; then
cp -f "$_src_conf_dir/$file" "$DAEMON_CFG_DIR/$config_file"
@ -278,22 +298,34 @@ function install_daemon()
log "\"$DAEMON_CFG_DIR/$config_file\" exists, skipping copy."
fi
done
#daemon_conf="$DAEMON_CFG_DIR/${DAEMON_NAME}.conf"
#daemon_log="$DAEMON_LOG_DIR/${DAEMON_NAME}.log"
#renaming of murano-api.conf->murano.conf and log file
daemon_conf="$(echo $DAEMON_CFG_DIR/${DAEMON_NAME}.conf | sed 's/-api//')"
daemon_conf_paste="$(echo $DAEMON_CFG_DIR/${DAEMON_NAME}-paste.ini | sed 's/-api//')"
daemon_log="$(echo $DAEMON_LOG_DIR/${DAEMON_NAME}.log | sed 's/-api//')"
mv -f $DAEMON_CFG_DIR/${DAEMON_NAME}.conf $daemon_conf
mv -f $DAEMON_CFG_DIR/${DAEMON_NAME}-paste.ini $daemon_conf_paste
#
log "Setting log file and sqlite db placement..."
iniset 'DEFAULT' 'log_file' "$(shslash $DAEMON_LOG_DIR/$DAEMON_NAME.log)" "$DAEMON_CFG_DIR/$DAEMON_NAME.conf"
iniset 'DEFAULT' 'verbose' 'True' "$DAEMON_CFG_DIR/$DAEMON_NAME.conf"
iniset 'DEFAULT' 'debug' 'True' "$DAEMON_CFG_DIR/$DAEMON_NAME.conf"
iniset 'database' 'connection' "$(shslash $DAEMON_DB_CONSTR)" "$DAEMON_CFG_DIR/$DAEMON_NAME.conf"
iniset 'DEFAULT' 'log_file' "$(shslash $daemon_log)" "$daemon_conf"
iniset 'DEFAULT' 'verbose' 'True' "$daemon_conf"
iniset 'DEFAULT' 'debug' 'True' "$daemon_conf"
iniset 'database' 'connection' "$(shslash $DAEMON_DB_CONSTR)" "$daemon_conf"
log "Searching daemon in \$PATH..."
get_service_exec_path || exit $?
log "...found at \"$SERVICE_EXEC_PATH\""
#get_service_exec_path || exit $?
#log "...found at \"$SERVICE_EXEC_PATH\""
log "Installing SysV init script."
inject_init || exit $?
prepare_db
if [ $? -eq 0 ]; then
iniset 'database' 'connection' "$(shslash $DAEMON_DB_CONSTR)" "$DAEMON_CFG_DIR/$DAEMON_NAME.conf"
iniset 'database' 'connection' "$(shslash $DAEMON_DB_CONSTR)" "$daemon_conf"
log "...database configuration finished."
fi
log "Everything done, please, verify \"$DAEMON_CFG_DIR/$DAEMON_NAME.conf\", service created as \"murano-api\"."
get_service_exec_path "murano-manage" || exit $?
log "Running murano-manage under $DAEMON_USER..."
su -c "$SERVICE_EXEC_PATH --config-file $daemon_conf db_sync" -s /bin/bash $DAEMON_USER >> $LOGFILE 2>&1
log "Everything done, please, verify \"$daemon_conf\", services created as \"murano-api,murano-engine\"."
}
function uninstall_daemon()
{