Skip to content

Instantly share code, notes, and snippets.

@cloudnull
Last active August 29, 2015 14:01
Show Gist options
  • Save cloudnull/3dd4c2b8925e420d4b94 to your computer and use it in GitHub Desktop.
Save cloudnull/3dd4c2b8925e420d4b94 to your computer and use it in GitHub Desktop.
Install Cinder Scheduler in a container
#!/usr/bin/env bash
# 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.
# This script makes the assumption that the you have installed the
# lxc-defiant template. If you have not installed the lxc-defiant template
# go here to get the latest version: https://github.com/cloudnull/lxc_defiant
# Variables:
# LXC_NAME="" # Name of the container, default "keystone1"
# LXC_DISTRO_NAME="" # Distro to deploy, default "precise"
# LXC_PASSWORD="" # Password for unix user, default "secrete"
# LXC_USERNAME="" # username for unix user, default "openstacl"
# LXC_NET_PREFIX="" # first three octets of IP address, default "10.0.0"
# LXC_NETMASK="" # subnet mask, default "255.255.255.0"
# LXC_IP_ADDR="" # last octet of IP for LXC container, default "200"
# LXC_GATEWAY="" # Default gateway, default "10.0.0.1"
# Enable Debug
# set -x
set -e -u -v
LXC_NAME=${LXC_NAME:-"cinder-scheduler"}
LXC_DISTRO_NAME=${LXC_DISTRO_NAME:-"precise"}
LXC_PASSWORD=${LXC_PASSWORD:-"secrete"}
LXC_USERNAME=${LXC_USERNAME:-"racker"}
LXC_NET_PREFIX=${LXC_NET_PREFIX:-"192.168.18"}
LXC_NETMASK=${LXC_NETMASK:-"255.255.255.0"}
LXC_IP_ADDR=${LXC_IP_ADDR:-$LXC_NET_PREFIX.246}
LXC_GATEWAY=${LXC_GATEWAY:-$LXC_NET_PREFIX.1}
# Create container
lxc-create --name ${LXC_NAME} \
--template defiant \
--config /etc/lxc/lxc-rpc.conf \
-- \
--bind-dir /openstack/cinder=/etc/cinder \
--release precise \
--max-ram 4096 \
--ip-address eth1=$LXC_IP_ADDR=255.255.255.0 \
--username $LXC_USERNAME \
--password $LXC_PASSWORD \
--optional-packages libmysqlclient-dev,mysql-client,curl,wget,iptables,python-dev,sshpass,git-core,sqlite3,build-essential,libssl-dev,libffi-dev,libxml2-dev,libxslt1-dev
# Start container
lxc-start -d --name $LXC_NAME
# Wait 5 seconds to get the container online
sleep 5
# Make sure SSH is good to go
lxc-attach --name $LXC_NAME <<EOL
update-rc.d ssh defaults
service ssh restart
EOL
# Install pip
lxc-attach --name $LXC_NAME <<EOL
curl https://bootstrap.pypa.io/get-pip.py | python
EOL
# Creating the glance directories
lxc-attach --name $LXC_NAME <<EOL
mkdir /var/log/cinder
mkdir /var/lib/cinder
mkdir /etc/cinder
mkdir /etc/cinder/rootwrap.d
mkdir /var/lock/cinder
mkdir /var/run/cinder
EOL
# Create glance group
lxc-attach --name $LXC_NAME <<EOL
groupadd --system \
cinder
EOL
# Create the glance user
lxc-attach --name $LXC_NAME <<EOL
useradd --gid cinder \
--create-home \
--home-dir /var/lib/cinder \
--shell /bin/false \
--system \
cinder
EOL
# Set ownership of all glance directories
lxc-attach --name $LXC_NAME <<EOL
chown -R cinder:cinder /var/log/cinder
chown -R cinder:cinder /var/lib/cinder
chown -R cinder:cinder /etc/cinder
chown -R cinder:cinder /var/lock/cinder
chown -R cinder:cinder /var/run/cinder
EOL
# Get the glance source
lxc-attach --name $LXC_NAME <<EOL
pushd /tmp
git clone https://github.com/openstack/cinder
pushd cinder
git checkout stable/icehouse
popd
popd
EOL
# Install the glance bits
lxc-attach --name $LXC_NAME <<EOL
pip install --allow-all-external pywbem
pip install mysql-python
pip install python-cinderclient
pip install /tmp/cinder
pushd /tmp/cinder/etc/cinder
for i in *
do
if [ ! -f "/etc/cinder/\$i" ]; then
cp \$i /etc/cinder/
fi
done
popd
pushd /tmp/cinder/etc/cinder/rootwrap.d
for i in *
do
if [ ! -f "/etc/cinder/\$i" ]; then
cp \$i /etc/cinder/rootwrap.d/
fi
done
popd
EOL
# Drop the init script
INIT_SCRIPT="/etc/init.d/cinder-scheduler"
PROGRAM_NAME="cinder-scheduler"
PROGRAM_INFO="Start and stop cinder-scheduler on boot"
PROGRAM_BINARY="/usr/local/bin/cinder-scheduler"
PROGRAM_PID_FILE="/var/run/cinder-scheduler.pid"
PROGRAM_USER="cinder"
PROGRAM_WORK_DIR="/var/lib/cinder"
PROGRAM_OPTIONS="-- --config-file=/etc/cinder/cinder.conf --log-file=/var/log/cinder/cinder-scheduler.log"
LXC_INIT_SCRIPT="/var/lib/lxc/$LXC_NAME/rootfs${INIT_SCRIPT}"
cat > $LXC_INIT_SCRIPT<<EOF
#! /usr/bin/env bash
### BEGIN INIT INFO
# Provides: ${PROGRAM_NAME}
# Required-Start: \$remote_fs \$syslog
# Required-Stop: \$remote_fs \$syslog
# Should-Start: \$named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: ${PROGRAM_INFO}
# Description: ${PROGRAM_INFO}
### END INIT INFO
set -e
SSD_OPTIONS="--start --background"
SSD_PID="--make-pidfile --pidfile ${PROGRAM_PID_FILE}"
SSD_CHROOT="--chuid ${PROGRAM_USER} --chdir ${PROGRAM_WORK_DIR}"
SSD="--exec ${PROGRAM_BINARY} ${PROGRAM_OPTIONS}"
# ---- Don't touch things after this line ----
source /lib/lsb/init-functions
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
program_start() {
if start-stop-daemon \${SSD_OPTIONS} \${SSD_PID} \${SSD_CHROOT} \${SSD}; then
rc=0
sleep 1
if ! kill -0 \$(cat "${PROGRAM_PID_FILE}") >/dev/null 2>&1; then
rc=1
fi
else
rc=1
fi
if [ \$rc -eq 0 ]; then
log_end_msg 0
else
log_failure_msg "${PROGRAM_NAME} daemon failed to start"
log_end_msg 1
rm -f "${PROGRAM_PID_FILE}"
fi
}
case "\$1" in
start)
log_daemon_msg "Starting ${PROGRAM_NAME} daemon" "${PROGRAM_NAME}"
if [ -s "${PROGRAM_PID_FILE}" ] && kill -0 \$(cat "${PROGRAM_PID_FILE}") >/dev/null 2>&1; then
log_progress_msg "${PROGRAM_NAME} is already running"
log_end_msg 0
exit 0
fi
program_start
;;
stop)
log_daemon_msg "Stopping ${PROGRAM_NAME} daemon" "${PROGRAM_NAME}"
start-stop-daemon --stop --quiet --oknodo --pidfile "${PROGRAM_PID_FILE}"
log_end_msg $?
rm -f "${PROGRAM_PID_FILE}"
;;
restart)
set +e
log_daemon_msg "Restarting ${PROGRAM_NAME} daemon" "${PROGRAM_NAME}"
if [ -s ${PROGRAM_PID_FILE} ] && kill -0 \$(cat "${PROGRAM_PID_FILE}") >/dev/null 2>&1; then
start-stop-daemon --stop --quiet --oknodo --pidfile "${PROGRAM_PID_FILE}" || true
sleep 1
else
log_warning_msg "${PROGRAM_NAME} daemon not running, attempting to start."
rm -f "${PROGRAM_PID_FILE}"
fi
program_start
;;
status)
status_of_proc -p "${PROGRAM_PID_FILE}" "${PROGRAM_BINARY}" ${PROGRAM_NAME}
exit $?
;;
*)
echo "Usage: /etc/init.d/${PROGRAM_NAME} {start|stop|restart|status}"
exit 1
esac
exit 0
EOF
lxc-attach --name $LXC_NAME <<EOL
chown root:root ${INIT_SCRIPT}
chmod 0755 ${INIT_SCRIPT}
update-rc.d ${PROGRAM_NAME} defaults
EOL

How to setup Cinder IceHouse

Create the MYSQL Database and grant privileges to the glance user. This only needs to be done once

mysql -h 23.253.238.179 \
      -u root \
      -p \
      -e "CREATE DATABASE cinder;"

mysql -h 23.253.238.179 \
      -u root \
      -p \
      -e "GRANT ALL PRIVILEGES ON glance.* TO 'cinder'@'%' IDENTIFIED BY 'passw0rd';"

setup the cinder.conf file

cat > /etc/cinder/cinder.conf<<EOF
[DEFAULT]
rpc_backend = rabbit
rabbit_hosts = 192.168.16.2:5672,192.168.16.3:5672,192.168.16.4:5672
lock_path = /var/lock/cinder
rootwrap_config = /etc/cinder/rootwrap.conf
api_paste_config = /etc/cinder/api-paste.ini
auth_strategy = keystone
#osapi_volume_listen = 192.168.18.203

verbose = True
debug = True

[database]
connection = mysql://cinder:[email protected]/cinder?charset=utf8

[keystone_authtoken]
auth_uri = http://23.253.238.179:5000/v2.0
identity_uri = http://23.253.238.179:35357/
signing_dir = /var/cache/cinder
admin_password = 0b4c235c6fa61fe147e3
admin_user = cinder
admin_tenant_name = service
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment