Add is_fedora and exit_distro_not_supported functions
Between is_fedora, is_ubuntu and is_suse, we can make the code a bit
simpler to read. We also use exit_distro_not_supported to identify
places where we need implementation details for new distros.
As "/sbin/service --skip-redirect" is Fedora-specific, guard this with a
is_fedora test too.
Change-Id: Ic77c0697ed9be0dbb5df8e73da93463e76025f0c
diff --git a/lib/cinder b/lib/cinder
index 9b9d50d..a43f0a1 100644
--- a/lib/cinder
+++ b/lib/cinder
@@ -195,8 +195,8 @@
mkdir -p $CINDER_STATE_PATH/volumes
if sudo vgs $VOLUME_GROUP; then
- if [[ "$os_PACKAGE" = "rpm" ]]; then
- # RPM doesn't start the service
+ if is_fedora || is_suse; then
+ # service is not started by default
start_service tgtd
fi
@@ -245,9 +245,15 @@
# do it in two steps
sudo stop tgt || true
sudo start tgt
- else
+ elif is_fedora; then
# bypass redirection to systemctl during restart
sudo /sbin/service --skip-redirect tgtd restart
+ elif is_suse; then
+ restart_service tgtd
+ else
+ # note for other distros: unstack.sh also uses the tgt/tgtd service
+ # name, and would need to be adjusted too
+ exit_distro_not_supported "restarting tgt"
fi
fi
diff --git a/lib/databases/mysql b/lib/databases/mysql
index 60ea143..68e9adc 100644
--- a/lib/databases/mysql
+++ b/lib/databases/mysql
@@ -23,22 +23,28 @@
if is_ubuntu; then
MY_CONF=/etc/mysql/my.cnf
MYSQL=mysql
- else
+ elif is_fedora; then
MY_CONF=/etc/my.cnf
- if is_suse; then
- MYSQL=mysql
- else
- MYSQL=mysqld
- fi
+ MYSQL=mysqld
+ elif is_suse; then
+ MY_CONF=/etc/my.cnf
+ MYSQL=mysql
+ else
+ exit_distro_not_supported "mysql configuration"
fi
# Start mysql-server
- if [[ "$os_PACKAGE" = "rpm" ]]; then
- # RPM doesn't start the service
+ if is_fedora || is_suse; then
+ # service is not started by default
start_service $MYSQL
- # Set the root password - only works the first time
+ fi
+
+ # Set the root password - only works the first time. For Ubuntu, we already
+ # did that with debconf before installing the package.
+ if ! is_ubuntu; then
sudo mysqladmin -u root password $DATABASE_PASSWORD || true
fi
+
# Update the DB to give user ‘$DATABASE_USER’@’%’ full control of the all databases:
sudo mysql -uroot -p$DATABASE_PASSWORD -h127.0.0.1 -e "GRANT ALL PRIVILEGES ON *.* TO '$DATABASE_USER'@'%' identified by '$DATABASE_PASSWORD';"
@@ -84,10 +90,12 @@
chmod 0600 $HOME/.my.cnf
fi
# Install mysql-server
- if is_suse; then
+ if is_ubuntu || is_fedora; then
+ install_package mysql-server
+ elif is_suse; then
install_package mysql-community-server
else
- install_package mysql-server
+ exit_distro_not_supported "mysql installation"
fi
}
diff --git a/lib/databases/postgresql b/lib/databases/postgresql
index d9c2f00..20ade85 100644
--- a/lib/databases/postgresql
+++ b/lib/databases/postgresql
@@ -20,7 +20,7 @@
function configure_database_postgresql {
echo_summary "Configuring and starting PostgreSQL"
- if [[ "$os_PACKAGE" = "rpm" ]]; then
+ if is_fedora || is_suse; then
PG_HBA=/var/lib/pgsql/data/pg_hba.conf
PG_CONF=/var/lib/pgsql/data/postgresql.conf
sudo [ -e $PG_HBA ] || sudo postgresql-setup initdb
@@ -53,10 +53,12 @@
else
sed -i "s/:root:\w\+/:root:$DATABASE_PASSWORD/" $PGPASS
fi
- if [[ "$os_PACKAGE" = "rpm" ]]; then
+ if is_ubuntu; then
+ install_package postgresql
+ elif is_fedora || is_suse; then
install_package postgresql-server
else
- install_package postgresql
+ exit_distro_not_supported "postgresql installation"
fi
}
diff --git a/lib/horizon b/lib/horizon
index 7321cbc..68337ab 100644
--- a/lib/horizon
+++ b/lib/horizon
@@ -81,19 +81,18 @@
sudo a2ensite horizon
# WSGI doesn't enable by default, enable it
sudo a2enmod wsgi
+ elif is_fedora; then
+ APACHE_NAME=httpd
+ APACHE_CONF=conf.d/horizon.conf
+ sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
+ elif is_suse; then
+ APACHE_NAME=apache2
+ APACHE_CONF=vhosts.d/horizon.conf
+ # Append wsgi to the list of modules to load
+ grep -q "^APACHE_MODULES=.*wsgi" /etc/sysconfig/apache2 ||
+ sudo sed '/^APACHE_MODULES=/s/^\(.*\)"$/\1 wsgi"/' -i /etc/sysconfig/apache2
else
- # Install httpd, which is NOPRIME'd
- if is_suse; then
- APACHE_NAME=apache2
- APACHE_CONF=vhosts.d/horizon.conf
- # Append wsgi to the list of modules to load
- grep -q "^APACHE_MODULES=.*wsgi" /etc/sysconfig/apache2 ||
- sudo sed '/^APACHE_MODULES=/s/^\(.*\)"$/\1 wsgi"/' -i /etc/sysconfig/apache2
- else
- APACHE_NAME=httpd
- APACHE_CONF=conf.d/horizon.conf
- sudo sed '/^Listen/s/^.*$/Listen 0.0.0.0:80/' -i /etc/httpd/conf/httpd.conf
- fi
+ exit_distro_not_supported "apache configuration"
fi
# Configure apache to run horizon
@@ -113,11 +112,13 @@
if is_ubuntu; then
# Install apache2, which is NOPRIME'd
install_package apache2 libapache2-mod-wsgi
+ elif is_fedora; then
+ sudo rm -f /etc/httpd/conf.d/000-*
+ install_package httpd mod_wsgi
elif is_suse; then
install_package apache2 apache2-mod_wsgi
else
- sudo rm -f /etc/httpd/conf.d/000-*
- install_package httpd mod_wsgi
+ exit_distro_not_supported "apache installation"
fi
# NOTE(sdague) quantal changed the name of the node binary
diff --git a/lib/nova b/lib/nova
index 3a4d34d..8272ef0 100644
--- a/lib/nova
+++ b/lib/nova
@@ -394,11 +394,13 @@
function install_nova() {
if is_service_enabled n-cpu; then
if is_ubuntu; then
- LIBVIRT_PKG_NAME=libvirt-bin
+ install_package libvirt-bin
+ elif is_fedora || is_suse; then
+ install_package libvirt
else
- LIBVIRT_PKG_NAME=libvirt
+ exit_distro_not_supported "libvirt installation"
fi
- install_package $LIBVIRT_PKG_NAME
+
# Install and configure **LXC** if specified. LXC is another approach to
# splitting a system into many smaller parts. LXC uses cgroups and chroot
# to simulate multiple systems.