From c18b96515279064c85cb7a71939d9e9de961d905 Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Tue, 4 Dec 2012 12:36:34 +0100 Subject: [PATCH] Add is_ubuntu function This replaces all of the [[ "$os_PACKAGE" = "deb" ]] tests, except when those tests are before straight calls to dpkg. Change-Id: I8a3ebf1b1bc5a55d736f9258d5ba1d24dabf04ea --- functions | 47 +++++++++++++++++++-------------------------- lib/cinder | 2 +- lib/databases/mysql | 4 ++-- lib/horizon | 6 +++--- lib/nova | 8 ++++---- lib/swift | 4 ++-- stack.sh | 4 ++-- tools/info.sh | 2 +- unstack.sh | 4 ++-- 9 files changed, 37 insertions(+), 44 deletions(-) diff --git a/functions b/functions index 794e474743..0911557fa4 100644 --- a/functions +++ b/functions @@ -341,6 +341,19 @@ function GetDistro() { } +# Determine if current distribution is an Ubuntu-based distribution. +# It will also detect non-Ubuntu but Debian-based distros; this is not an issue +# since Debian and Ubuntu should be compatible. +# is_ubuntu +function is_ubuntu { + if [[ -z "$os_PACKAGE" ]]; then + GetOSVersion + fi + + [ "$os_PACKAGE" = "deb" ] +} + + # Determine if current distribution is a SUSE-based distribution # (openSUSE, SLE). # is_suse @@ -580,11 +593,7 @@ function disable_negated_services() { # Distro-agnostic package installer # install_package package [package ...] function install_package() { - if [[ -z "$os_PACKAGE" ]]; then - GetOSVersion - fi - - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then [[ "$NO_UPDATE_REPOS" = "True" ]] || apt_get update NO_UPDATE_REPOS=True @@ -609,6 +618,7 @@ function is_package_installed() { if [[ -z "$os_PACKAGE" ]]; then GetOSVersion fi + if [[ "$os_PACKAGE" = "deb" ]]; then dpkg -l "$@" > /dev/null return $? @@ -661,10 +671,7 @@ function pip_install { # Service wrapper to restart services # restart_service service-name function restart_service() { - if [[ -z "$os_PACKAGE" ]]; then - GetOSVersion - fi - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then sudo /usr/sbin/service $1 restart else sudo /sbin/service $1 restart @@ -746,10 +753,7 @@ function setup_develop() { # Service wrapper to start services # start_service service-name function start_service() { - if [[ -z "$os_PACKAGE" ]]; then - GetOSVersion - fi - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then sudo /usr/sbin/service $1 start else sudo /sbin/service $1 start @@ -760,10 +764,7 @@ function start_service() { # Service wrapper to stop services # stop_service service-name function stop_service() { - if [[ -z "$os_PACKAGE" ]]; then - GetOSVersion - fi - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then sudo /usr/sbin/service $1 stop else sudo /sbin/service $1 stop @@ -1031,11 +1032,7 @@ function add_user_to_group() { function get_rootwrap_location() { local module=$1 - if [[ -z "$os_PACKAGE" ]]; then - GetOSVersion - fi - - if [[ "$os_PACKAGE" = "deb" ]] || is_suse; then + if is_ubuntu || is_suse; then echo "/usr/local/bin/$module-rootwrap" else echo "/usr/bin/$module-rootwrap" @@ -1045,11 +1042,7 @@ function get_rootwrap_location() { # Get the path to the pip command. # get_pip_command function get_pip_command() { - if [[ -z "$os_PACKAGE" ]]; then - GetOSVersion - fi - - if [[ "$os_PACKAGE" = "deb" ]] || is_suse; then + if is_ubuntu || is_suse; then echo "/usr/bin/pip" else echo "/usr/bin/pip-python" diff --git a/lib/cinder b/lib/cinder index 1aa34cd207..ce160bf0c1 100644 --- a/lib/cinder +++ b/lib/cinder @@ -237,7 +237,7 @@ function _configure_tgt_for_config_d() { # start_cinder() - Start running processes, including screen function start_cinder() { if is_service_enabled c-vol; then - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then _configure_tgt_for_config_d if [[ ! -f /etc/tgt/conf.d/cinder.conf ]]; then echo "include $CINDER_STATE_PATH/volumes/*" | sudo tee /etc/tgt/conf.d/cinder.conf diff --git a/lib/databases/mysql b/lib/databases/mysql index eb84f2ca40..60ea143f73 100644 --- a/lib/databases/mysql +++ b/lib/databases/mysql @@ -20,7 +20,7 @@ function recreate_database_mysql { function configure_database_mysql { echo_summary "Configuring and starting MySQL" - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then MY_CONF=/etc/mysql/my.cnf MYSQL=mysql else @@ -61,7 +61,7 @@ default-storage-engine = InnoDB" $MY_CONF } function install_database_mysql { - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then # Seed configuration with mysql password so that apt-get install doesn't # prompt us for a password upon install. cat < natty ]]; then cgline="none /cgroup cgroup cpuacct,memory,devices,cpu,freezer,blkio 0 0" sudo mkdir -p /cgroup @@ -228,7 +228,7 @@ cgroup_device_acl = [ EOF fi - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then LIBVIRT_DAEMON=libvirt-bin else # http://wiki.libvirt.org/page/SSHPolicyKitSetup @@ -393,7 +393,7 @@ function install_novaclient() { # install_nova() - Collect source and prepare function install_nova() { if is_service_enabled n-cpu; then - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then LIBVIRT_PKG_NAME=libvirt-bin else LIBVIRT_PKG_NAME=libvirt @@ -403,7 +403,7 @@ function install_nova() { # splitting a system into many smaller parts. LXC uses cgroups and chroot # to simulate multiple systems. if [[ "$LIBVIRT_TYPE" == "lxc" ]]; then - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then if [[ "$DISTRO" > natty ]]; then install_package cgroup-lite fi diff --git a/lib/swift b/lib/swift index 366c467bf4..140e5e9b7d 100644 --- a/lib/swift +++ b/lib/swift @@ -159,7 +159,7 @@ function configure_swift() { s,%SWIFT_DATA_DIR%,$SWIFT_DATA_DIR,; " $FILES/swift/rsyncd.conf | sudo tee /etc/rsyncd.conf # rsyncd.conf just prepared for 4 nodes - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then sudo sed -i '/^RSYNC_ENABLE=false/ { s/false/true/ }' /etc/default/rsync else sudo sed -i '/disable *= *yes/ { s/yes/no/ }' /etc/xinetd.d/rsync @@ -341,7 +341,7 @@ function start_swift() { # (re)start rsyslog restart_service rsyslog # Start rsync - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then sudo /etc/init.d/rsync restart || : else sudo systemctl start xinetd.service diff --git a/stack.sh b/stack.sh index 55eafa824c..942835635f 100755 --- a/stack.sh +++ b/stack.sh @@ -677,7 +677,7 @@ set -o xtrace # Install package requirements echo_summary "Installing package prerequisites" -if [[ "$os_PACKAGE" = "deb" ]]; then +if is_ubuntu; then install_package $(get_packages $FILES/apts) elif is_suse; then install_package $(get_packages $FILES/rpms-suse) @@ -726,7 +726,7 @@ if is_service_enabled q-agt; then if is_quantum_ovs_base_plugin "$Q_PLUGIN"; then # Install deps # FIXME add to ``files/apts/quantum``, but don't install if not needed! - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then kernel_version=`cat /proc/version | cut -d " " -f3` install_package make fakeroot dkms openvswitch-switch openvswitch-datapath-dkms linux-headers-$kernel_version else diff --git a/tools/info.sh b/tools/info.sh index a872d59d18..583a9949dd 100755 --- a/tools/info.sh +++ b/tools/info.sh @@ -88,7 +88,7 @@ done # - We are going to check packages only for the services needed. # - We are parsing the packages files and detecting metadatas. -if [[ "$os_PACKAGE" = "deb" ]]; then +if is_ubuntu; then PKG_DIR=$FILES/apts else PKG_DIR=$FILES/rpms diff --git a/unstack.sh b/unstack.sh index 20ba17b66b..81ce088a86 100755 --- a/unstack.sh +++ b/unstack.sh @@ -65,7 +65,7 @@ if is_service_enabled cinder; then # If tgt driver isn't running this won't work obviously # So check the response and restart if need be echo "tgtd seems to be in a bad state, restarting..." - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then restart_service tgt else restart_service tgtd @@ -85,7 +85,7 @@ if is_service_enabled cinder; then sudo rm -rf $CINDER_STATE_PATH/volumes/* fi - if [[ "$os_PACKAGE" = "deb" ]]; then + if is_ubuntu; then stop_service tgt else stop_service tgtd