Consolidate common OS installation into a script:

Move common openstack service installation operations
into a new script `os-svc-install`, which simplifies
the elements for openstack services.

Change-Id: Ied8ac3278e7fe8af76e24748ec4e598a84afa03c
This commit is contained in:
Tim Miller 2013-01-25 14:23:56 -08:00
parent 8220c00095
commit 56e50ee5cf
19 changed files with 115 additions and 181 deletions

View File

@ -2,13 +2,13 @@
# #
# Copyright 2012 Hewlett-Packard Development Company, L.P. # Copyright 2012 Hewlett-Packard Development Company, L.P.
# All Rights Reserved. # All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
# a copy of the License at # a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@ -29,7 +29,7 @@ source $_LIB/die
function show_options () { function show_options () {
echo "Options:" echo "Options:"
echo " -a i386|amd64 -- set the architecture of the image" echo " -a i386|amd64 -- set the architecture of the image"
echo " -o filename -- set the name of the output file" echo " -o filename -- set the name of the output file"
echo " -x -- turn on tracing" echo " -x -- turn on tracing"
echo " -u -- uncompressed; do not compress the image - larger but faster" echo " -u -- uncompressed; do not compress the image - larger but faster"
echo " -c -- clear environment before starting work" echo " -c -- clear environment before starting work"
@ -92,13 +92,13 @@ qemu-img create -f qcow2 -o preallocation=metadata $TMP_IMAGE_PATH ${IMAGE_SIZE}
# Should have a grab-next-dev helper ? # Should have a grab-next-dev helper ?
NBD_DEV=/dev/nbd0 NBD_DEV=/dev/nbd0
if [[ $(qemu-nbd --help | grep cache) == *writeback* ]] ; then if [[ $(qemu-nbd --help | grep cache) == *writeback* ]] ; then
CACHE="--cache=writeback" CACHE="--cache=writeback"
else else
echo "Warning: qemu-nbd without --cache=writeback is /slow/." echo "Warning: qemu-nbd without --cache=writeback is /slow/."
CACHE="" CACHE=""
fi fi
sudo qemu-nbd -c $NBD_DEV $CACHE $TMP_IMAGE_PATH sudo qemu-nbd -c $NBD_DEV $CACHE $TMP_IMAGE_PATH
export EXTRA_UNMOUNT="sudo qemu-nbd -d $NBD_DEV" export EXTRA_UNMOUNT="sudo qemu-nbd -d $NBD_DEV"
export IMAGE_BLOCK_DEVICE=$NBD_DEV export IMAGE_BLOCK_DEVICE=$NBD_DEV
eval_run_d block-device "IMAGE_BLOCK_DEVICE=" eval_run_d block-device "IMAGE_BLOCK_DEVICE="

View File

@ -0,0 +1 @@
os-svc-install

View File

@ -1,7 +0,0 @@
#!/bin/bash
set -e
set -o xtrace
# upstart script
cp -f $(dirname $0)/etc_init_glance-api.conf /etc/init/glance-api.conf

View File

@ -1,9 +0,0 @@
description "OpenStack Glance API service"
start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [016]
respawn
exec su -s /bin/sh -c "exec /opt/stack/glance/bin/glance-api --config-file /etc/glance/glance-api.conf --log-config /etc/glance/logging.conf"

View File

@ -1,32 +1,4 @@
#!/bin/sh #!/bin/sh
set -eux
# install glance-api os-svc-install -n glance-api -u glance -r https://github.com/openstack/glance.git -c "/opt/stack/glance/bin/glance-api"
set -e
set -o xtrace
install-packages \
python-pip git-core python-setuptools python-dev python-lxml python-netaddr \
python-pastescript python-pastedeploy python-paste python-sqlalchemy \
python-greenlet python-routes python-simplejson python-webob rabbitmq-server
OS_ROOT=/opt/stack
mkdir -p $OS_ROOT
# clone source
GLANCE_ROOT=$OS_ROOT/glance
git clone https://github.com/openstack/glance.git $GLANCE_ROOT
cd $GLANCE_ROOT
git checkout master
# pip dependencies
python setup.py egg_info
pip install -r glance.egg-info/requires.txt
cd -
# config
mkdir -p /etc/glance
cp $GLANCE_ROOT/etc/glance-api.conf /etc/glance
cp $GLANCE_ROOT/etc/policy.json /etc/glance
cp $GLANCE_ROOT/etc/glance-api-paste.ini /etc/glance
cp $GLANCE_ROOT/etc/logging.cnf.sample /etc/glance/logging.conf

View File

@ -0,0 +1 @@
os-svc-install

View File

@ -1,7 +0,0 @@
#!/bin/bash
set -e
set -o xtrace
# upstart script
cp -f $(dirname $0)/etc_init_keystone.conf /etc/init/keystone.conf

View File

@ -1,9 +0,0 @@
description "OpenStack Keystone service"
start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [016]
respawn
exec su -s /bin/sh -c "exec /opt/stack/keystone/bin/keystone-all"

View File

@ -1,32 +1,4 @@
#!/bin/sh #!/bin/bash
set -eux
# install keystone os-svc-install -n keystone -u keystone -r https://github.com/openstack/keystone.git -c "/opt/stack/keystone/bin/keystone-all"
set -e
set -o xtrace
install-packages \
python-pip git-core python-setuptools python-dev python-lxml python-netaddr \
python-pastescript python-pastedeploy python-paste python-sqlalchemy \
python-greenlet python-routes python-simplejson python-webob
OS_ROOT=/opt/stack
mkdir -p $OS_ROOT
# clone source
KEYSTONE_ROOT=$OS_ROOT/keystone
git clone https://github.com/openstack/keystone.git $KEYSTONE_ROOT
cd $KEYSTONE_ROOT
git checkout master
# pip dependencies
python setup.py egg_info
pip install -r keystone.egg-info/requires.txt
cd -
# config
mkdir -p /etc/keystone
cp $KEYSTONE_ROOT/etc/keystone.conf.sample /etc/keystone/keystone.conf
cp $KEYSTONE_ROOT/etc/policy.json /etc/keystone
cp $KEYSTONE_ROOT/etc/logging.conf.sample /etc/keystone/logging.conf

View File

@ -0,0 +1 @@
os-svc-install

View File

@ -1,39 +1,5 @@
#!/bin/sh #!/bin/sh
set -eux set -eux
useradd -G admin -m nova -s /bin/false os-svc-install -n nova-api -u nova -r https://github.com/openstack/nova.git -c "/opt/stack/nova/bin/nova-api"
install-packages \
python-pip git-core python-setuptools python-dev python-lxml python-netaddr \
python-pastescript python-pastedeploy python-paste python-sqlalchemy \
python-greenlet python-routes python-simplejson python-webob rabbitmq-server
OS_ROOT=/opt/stack
mkdir -p $OS_ROOT
# clone source
NOVA_ROOT=$OS_ROOT/nova
git clone https://github.com/openstack/nova.git $NOVA_ROOT
cd $NOVA_ROOT
git checkout master
# pip dependencies
python setup.py egg_info
pip install -r nova.egg-info/requires.txt
cd -
SYS_DIRS="/etc/nova /var/log/nova $NOVA_ROOT/keys"
for d in $SYS_DIRS; do
mkdir -p $d
chown nova:nova $d
done
# config
cp $NOVA_ROOT/etc/nova/nova.conf.sample /etc/nova/nova.conf
cp $NOVA_ROOT/etc/nova/logging_sample.conf /etc/nova/logging.conf
cp $NOVA_ROOT/etc/nova/api-paste.ini /etc/nova
cp $NOVA_ROOT/etc/nova/policy.json /etc/nova
# upstart script
cp -f $(dirname $0)/../upstart/nova-api.conf /etc/init

View File

@ -1,30 +0,0 @@
description "OpenStack Nova API Service"
start on runlevel [2345]
stop on runlevel [016]
setuid nova
setgid nova
respawn
exec /opt/stack/nova/bin/nova-api
# wait until service is running.
post-start script
svc_port=$(grep ^osapi_compute_listen_port /etc/nova/nova.conf ||:)
svc_port=${svc_port##*=}
if [ -z "$svc_port" ] ; then
svc_port="8774"
fi
for try in $(seq 9 -1 1); do
if nc -w 1 localhost $svc_port < /dev/null ; then
echo Connected to port $svc_port!
exit 0
fi
echo Could not connect to $svc_port, retrying $try more times...
sleep 1
done
end script

View File

@ -0,0 +1,9 @@
Installs 'os-svc-install', a script to perform one-line installs of init-controlled openstack services from github.
Example Usage
--------------
`os-svc-install -u nova -n nova-all -c 'nova-all --someoption' -r https://github.com/openstack/nova.git`
The above command will pip-install the repo specified by '-r', and create a service start script called nova-all (from `-n`), which starts the command specified by `-c` as user `-u`

View File

@ -0,0 +1,7 @@
#!/bin/bash
set -eux
install-packages python-pip
install -m 0755 -o root -g root $(dirname $0)/../os-svc-install /usr/local/bin/os-svc-install

View File

@ -0,0 +1,68 @@
#!/bin/bash
set -e
function install-os-upstart() {
local svc_name=$1
local svc_user=$2
local cmd=$3
local f=/etc/init/$svc_name.conf
cat > $f <<EOF
description "OpenStack $svc_name service"
start on runlevel [2345]
stop on runlevel [016]
setuid $svc_user
respawn
exec $cmd
EOF
}
function install-os-service() {
local svc_name=$1
local svc_user=$2
local svc_repo=$3
local os_root=/opt/stack
mkdir -p $os_root
id $svc_user || useradd $svc_user --system -d $os_root -s /bin/false
pip install --src $os_root -e git+$svc_repo#egg=$svc_name
}
function usage() {
echo "options:"
echo " -h show usage and exit"
echo " -r service's git repo url"
echo " -n service name"
echo " -u name of the service run-as user"
echo " -c command line to start service"
exit 0
}
while getopts r:u:c:n:h opt; do
case "$opt" in
u) user=$OPTARG;;
h) usage;;
r) repo=$OPTARG;;
n) name=$OPTARG;;
c) cmd=$OPTARG;;
\?) usage;;
esac
done
if [[ -z "$user" || -z "$repo" || -z "$cmd" || -z "$name" ]]; then
echo "missing required parameter"
exit 1
fi
install-packages python-dev python-pip git-core python-setuptools gcc libc6-dev libxml2-dev libxslt-dev
install-os-service "$name" "$user" "$repo"
install-os-upstart "$name" "$user" "$cmd"

View File

@ -1,12 +1,12 @@
# Copyright 2012 Hewlett-Packard Development Company, L.P. # Copyright 2012 Hewlett-Packard Development Company, L.P.
# All Rights Reserved. # All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
# a copy of the License at # a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@ -38,7 +38,7 @@ function save_image () {
function generate_hooks () { function generate_hooks () {
mkdir -p $TMP_HOOKS_PATH mkdir -p $TMP_HOOKS_PATH
for _ELEMENT in $IMAGE_ELEMENT ; do for _ELEMENT in $IMAGE_ELEMENT ; do
[ -d $ELEMENTS_DIR/$_ELEMENT ] || die "Element $_ELEMENT does not exist." ; [ -d $ELEMENTS_DIR/$_ELEMENT ] || die "Element $_ELEMENT does not exist." ;
cp -t $TMP_HOOKS_PATH -a $ELEMENTS_DIR/$_ELEMENT/* ; cp -t $TMP_HOOKS_PATH -a $ELEMENTS_DIR/$_ELEMENT/* ;
done done
@ -80,9 +80,9 @@ function eval_run_d () {
function map_nbd { function map_nbd {
(lsmod | grep '^nbd ') || sudo modprobe nbd max_part=16 (lsmod | grep '^nbd ') || sudo modprobe nbd max_part=16
if [[ $(qemu-nbd --help | grep cache) == *writeback* ]] ; then if [[ $(qemu-nbd --help | grep cache) == *writeback* ]] ; then
CACHE="--cache=writeback" CACHE="--cache=writeback"
else else
echo "Warning: qemu-nbd without --cache=writeback is /slow/." echo "Warning: qemu-nbd without --cache=writeback is /slow/."
CACHE="" CACHE=""
fi fi

View File

@ -1,12 +1,12 @@
# Copyright 2012 Hewlett-Packard Development Company, L.P. # Copyright 2012 Hewlett-Packard Development Company, L.P.
# All Rights Reserved. # All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
# a copy of the License at # a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@ -20,6 +20,6 @@ FS_TYPE=${FS_TYPE:-ext4}
IMAGE_TYPE=${IMAGE_TYPE:-qcow2} IMAGE_TYPE=${IMAGE_TYPE:-qcow2}
IMAGE_NAME=${IMAGE_NAME:-image} IMAGE_NAME=${IMAGE_NAME:-image}
export IMAGE_SIZE=${IMAGE_SIZE:-2} # N.B. This size is in GB export IMAGE_SIZE=${IMAGE_SIZE:-2} # N.B. This size is in GB
# Set via the CLI normally. # Set via the CLI normally.
# IMAGE_ELEMENT= # IMAGE_ELEMENT=
export ELEMENTS_DIR=$(dirname $0)/../elements export ELEMENTS_DIR=$(dirname $0)/../elements

View File

@ -1,12 +1,12 @@
# Copyright 2012 Hewlett-Packard Development Company, L.P. # Copyright 2012 Hewlett-Packard Development Company, L.P.
# All Rights Reserved. # All Rights Reserved.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
# a copy of the License at # a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, software # Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@ -242,4 +242,3 @@ function copy_elements_lib () {
sudo mkdir -p $TMP_MOUNT_PATH/lib/diskimage-builder sudo mkdir -p $TMP_MOUNT_PATH/lib/diskimage-builder
sudo cp -t $TMP_MOUNT_PATH/lib/diskimage-builder $_LIB/elements-functions sudo cp -t $TMP_MOUNT_PATH/lib/diskimage-builder $_LIB/elements-functions
} }

View File

@ -36,7 +36,7 @@ function ensure_binaries() {
for _LINE in $(cat $_FILE) ; do for _LINE in $(cat $_FILE) ; do
BINARY_DEPS="${BINARY_DEPS} $_LINE" BINARY_DEPS="${BINARY_DEPS} $_LINE"
done done
fi fi
done done
for _BIN in $BINARY_DEPS ; do for _BIN in $BINARY_DEPS ; do
@ -144,7 +144,7 @@ function populate_init () {
# init fragment from ${_FLVR} # init fragment from ${_FLVR}
EOF EOF
cat <$_FILE >>$TMP_MOUNT_PATH/init cat <$_FILE >>$TMP_MOUNT_PATH/init
fi fi
done done
# Add our final steps to /init # Add our final steps to /init