#!/bin/bash # vim: tabstop=4 shiftwidth=4 softtabstop=4 # # Copyright (C) 2012, Red Hat, Inc. # Angus Salkeld # Steven Dake # # 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. # sleep 1 = systemd's definition of start is different from mine BASE_DIR=`dirname $0` if [[ $1 = '--with-cinder' ]]; then with_cinder=1 else with_cinder=0 fi FEDORA_VERSION=$(cat /etc/fedora-release | awk '{print $3}') if [[ $FEDORA_VERSION -gt 17 || $with_cinder -eq 1 ]]; then VOLUME_SERVICE="openstack-cinder" VOLUME_PATH="/var/lib/cinder/cinder-volumes.img" VOLUME_NAME="cinder-volumes" else VOLUME_SERVICE="openstack-nova" VOLUME_PATH="/var/lib/nova/nova-volumes.img" VOLUME_NAME="nova-volumes" fi action=$1 if [ -z "$action" ] then echo "openstack [start|stop|install|erase|status]" echo echo "This tool is designed to control OpenStack on a Fedora 16+ system" echo echo "start - Starts OpenStack" echo "stop - Stops OpenStack" echo "restart - Restart OpenStack" echo "install - Installs a fresh OpenStack system with Keystone from RPM repostories" echo "erase - permanently destroys an existing installation of OpenStack" echo "status - show service status for all required OpenStack services" fi os_dist='unknown' function check_os_version() { #determine which OpenStack version we'll be running os_version=$(rpm -q openstack-nova-common --qf='%{VERSION}') case $os_version in 2012.1|2012.1.*) os_dist='essex';; 2012.2|2012.2.*) os_dist='folsom';; 2013.1|2013.1.*) os_dist='grizzly';; *) echo 'Could not detect installed OpenStack version';; esac echo "Detected os_version $os_version os_dist=$os_dist" } function os_status() { for service in ${OS_SERVICES[@]} do output=$(systemctl show "$service.service" --property=ActiveState) running=(${output//=/ }) #ActiveState=active echo "$service ${running[1]}" | awk '{ printf "%-40s %s\n", $1, $2}' done } OS_STATUS="OK" function os_check_status() { # If a service is not running, we try again up to MAX_TRIES times MAX_TRIES=5 for service in ${OS_SERVICES[@]} do attempts=0 while [[ ${attempts} < ${MAX_TRIES} ]] do attempts=$((${attempts} + 1)) output=$(systemctl show "$service.service" --property=ActiveState) running=${output#ActiveState=} #ActiveState=active if [[ ${running} != "active" ]] then echo "Service ${service} does not seem to be running, waiting 1s ${attempts}/${MAX_TRIES}" OS_STATUS="FAIL ${service} : ${running}" sleep 1 else echo "${service} ${running}" | awk '{ printf "%-40s %s\n", $1, $2}' OS_STATUS="OK" break fi done # If we get here and OS_STATUS != OK then we return as something failed if [[ ${OS_STATUS} != "OK" ]] then echo "Service ${service} has failed to start, check logs for errors" break fi done } function os_start() { action=start sudo systemctl $action qpidd.service mysqld.service sleep 1 sudo systemctl $action openstack-keystone.service tgtd.service sleep 1 for svc in api registry do sudo systemctl $action openstack-glance-$svc.service done if ! sudo vgs | grep -q $VOLUME_NAME; then sudo vgcreate $VOLUME_NAME $(sudo losetup --show -f $VOLUME_PATH) fi for svc in api cert objectstore compute scheduler do sudo systemctl $action openstack-nova-$svc.service done sudo systemctl $action $VOLUME_SERVICE-volume.service if [[ $VOLUME_SERVICE == "openstack-cinder" ]]; then for svc in api scheduler do sudo systemctl $action $VOLUME_SERVICE-$svc.service done fi # This must be started after openstack-nova-cert due to an SELinux # policy problem. See https://bugzilla.redhat.com/show_bug.cgi?id=857747 sleep 2 sudo systemctl $action openstack-nova-network.service # conductor service is new for grizzly if [ "$os_dist" = 'grizzly' ]; then sudo systemctl $action openstack-nova-conductor.service fi } function os_stop() { action=stop sudo systemctl $action openstack-keystone.service tgtd.service for svc in api objectstore compute network scheduler cert do sudo systemctl $action openstack-nova-$svc.service done sudo systemctl $action $VOLUME_SERVICE-volume.service if [[ $VOLUME_SERVICE == "openstack-cinder" ]]; then for svc in api scheduler do sudo systemctl $action $VOLUME_SERVICE-$svc.service done fi for svc in api registry do sudo systemctl $action openstack-glance-$svc.service done } function os_restart() { action=restart os_stop sleep 1 os_start } function os_erase() { for net in `sudo nova-manage network list | awk '/^[[:digit:]]/ { print $9 }'` do sudo nova-manage network delete --uuid $net done os_stop sleep 1 # Kill dnsmasq processes if find /var/lib/nova/networks -name '*.pid'; then sudo kill `cat /var/lib/nova/networks/*.pid` fi sudo rm -f /var/lib/libvirt/qemu/save/instance-000* sudo rm -f /var/lib/libvirt/qemu/instance-000* sudo yum -q -y erase python-glance* python-nova* python-keystone* openstack-swift* openstack-dashboard sudo systemctl start mysqld.service sleep 1 sudo openstack-db --yes --service nova --drop $* sudo openstack-db --yes --service glance --drop $* sudo openstack-db --yes --service keystone --drop $* if [[ $VOLUME_SERVICE == "openstack-cinder" ]]; then sudo openstack-db --yes --service cinder --drop $* fi sudo yum -q -y erase openstack-utils sudo vgchange -an $VOLUME_NAME sudo losetup -d /dev/loop0 sudo rm -f $VOLUME_PATH sudo rm -rf /etc/{glance,nova,swift,keystone,openstack-dashboard,cinder} /var/lib/{glance,nova,swift,keystone,cinder} /var/log/{glance,nova,swift,keystone,cinder} /var/run/{glance,nova,swift,keystone,cinder} rm -f $HOME/.openstack/.keystonerc } function os_install() { sudo yum -q -y groupinstall Virtualization sudo yum -q -y install openstack-utils openstack-nova openstack-glance openstack-keystone openstack-dashboard scsi-target-utils qpid-cpp-server qpid-cpp-server-daemon $VOLUME_SERVICE check_os_version sudo dd if=/dev/zero of=$VOLUME_PATH bs=1M seek=20k count=0 # Note if mysql-server is not installed, this will fail # and openstack-db --yes will install/start it sudo systemctl start mysqld.service sudo systemctl enable libvirtd.service sudo systemctl start libvirtd.service sleep 1 # Configure the databases sudo openstack-db --yes --service nova --init $* sudo openstack-db --yes --service glance --init $* sudo openstack-db --yes --service keystone --init $* if [[ $VOLUME_SERVICE == "openstack-cinder" ]]; then sudo openstack-db --yes --service cinder --init $* fi # Create a keystone RC file # Note that keystone bug #1073291 "fix" removes a chunk of stuff from # /usr/share/openstack-keystone/sample_data.sh (called from # openstack-keystone-sample-data below), so for grizzly we have to align # our RC file with the hardcoded values, because the password variables # are now ignored, also the admin tenant is no longer created. # I raised bug #1166182 to potentially fix this, but for now workaround: mkdir -p $HOME/.openstack if [ "$os_dist" = 'grizzly' ]; then cat > $HOME/.openstack/keystonerc < $HOME/.openstack/keystonerc <