]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Make heat-db-setup generic enough to run on RPM or DEB distributions
authorSteven Dake <sdake@redhat.com>
Tue, 24 Apr 2012 22:29:08 +0000 (15:29 -0700)
committerSteven Dake <sdake@redhat.com>
Tue, 24 Apr 2012 22:29:30 +0000 (15:29 -0700)
Signed-off-by: Steven Dake <sdake@redhat.com>
bin/heat-db-setup [moved from bin/heat-db-setup-fedora with 82% similarity]
setup.py

similarity index 82%
rename from bin/heat-db-setup-fedora
rename to bin/heat-db-setup
index 9dc63749a170ea2a99fc15e845f05b7841d88ee1..5eef22968ec4aba73d70226938af974259718d1f 100755 (executable)
@@ -23,8 +23,10 @@ Set up a local MySQL database for use with heat.
 This script will create a 'heat' database that is accessible
 only on localhost by user 'heat' with password 'heat'.
 
-Usage: heat-db-setup [options]
+Usage: heat-db-setup <rpm|deb> [options]
 Options:
+       select a distro type (rpm or debian)
+
        --help        | -h
                Print usage information.
        --heatpw <pw> | -n <pw>
@@ -49,14 +51,14 @@ EOF
 
 install_mysql_server() {
        if [ -z "${ASSUME_YES}" ] ; then
-               yum install mysql-server
+               $PACKAGE_INSTALL mysql-server
        else
-               yum install -y mysql-server
+               $PACKAGE_INSTALL -y mysql-server
        fi
 }
 
 start_mysql_server() {
-       systemctl start mysqld.service
+       $SERVICE_START
 }
 
 MYSQL_HEAT_PW_DEFAULT="heat"
@@ -64,6 +66,32 @@ MYSQL_HEAT_PW=${MYSQL_HEAT_PW_DEFAULT}
 HEAT_CONFIG="/etc/heat/heat-engine.conf"
 ASSUME_YES=""
 
+if [ $# -eq 0 ]
+then
+       usage
+fi
+
+case "$1" in
+       rpm)
+               echo "Installing on an RPM system."
+               PACKAGE_INSTALL="yum install"
+               PACKAGE_STATUS="rpm -q"
+               SERVICE_MYSQLD="mysqld"
+               SERVICE_START="service $SERVICE_MYSQLD start"
+               SERVICE_STATUS="service $SERVICE_MYSQLD status"
+               SERVICE_ENABLE="chkconfig"
+               ;;
+       deb)
+               echo "Installing on a Debian system."
+               PACKAGE_INSTALL="apt-get install"
+               PACKAGE_STATUS="dpkg-query -s"
+               SERVICE_MYSQLD="mysql"
+               SERVICE_START="service $SERVICE_MYSQLD start"
+               SERVICE_STATUS="service $SERVICE_MYSQLD status"
+               SERVICE_ENABLE=""
+               ;;
+esac
+
 while [ $# -gt 0 ]
 do
        case "$1" in
@@ -93,7 +121,7 @@ done
 # Make sure MySQL is installed.
 
 NEW_MYSQL_INSTALL=0
-if ! rpm -q mysql-server > /dev/null
+if ! $PACKAGE_STATUS mysql-server > /dev/null
 then
        if [ -z "${ASSUME_YES}" ] ; then
                printf "mysql-server is not installed.  Would you like to install it now? (y/n): "
@@ -118,16 +146,16 @@ fi
 
 # Make sure mysqld is running.
 
-if ! systemctl status mysqld.service > /dev/null
+if ! $SERVICE_STATUS > /dev/null
 then
        if [ -z "${ASSUME_YES}" ] ; then
-               printf "mysqld is not running.  Would you like to start it now? (y/n): "
+               printf "$MYSQL_SERVICE is not running.  Would you like to start it now? (y/n): "
                read response
                case "$response" in
                        y|Y)
                                ;;
                        n|N)
-                               echo "mysqld must be running.  Please start it before proceeding."
+                               echo "$MYSQL_SERVICE must be running.  Please start it before proceeding."
                                exit 0
                                ;;
                        *)
@@ -139,7 +167,7 @@ then
        start_mysql_server
 
        # If we both installed and started, ensure it starts at boot
-       [ $NEW_MYSQL_INSTALL -eq 1 ] && chkconfig mysqld on
+       [ $NEW_MYSQL_INSTALL -eq 1 ] && $SERVICE_ENABLE $SERVICE_MYSQLD on
 fi
 
 
index 1837ae02a2b8e268ab36dc13f4be056a1b80854d..a26c2cc0710a33fb643e1827df530c71c6277e1d 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -90,7 +90,7 @@ setup(
     scripts=['bin/heat',
              'bin/heat-api',
              'bin/heat-engine',
-             'bin/heat-db-setup-fedora'],
+             'bin/heat-db-setup'],
     data_files=[('/etc/heat', ['etc/heat-api.conf',
                                'etc/heat-api-paste.ini',
                                'etc/heat-engine.conf',