From 56e50ee5cf4dde5362eb9a0b747a2ca04b49f8f0 Mon Sep 17 00:00:00 2001 From: Tim Miller Date: Fri, 25 Jan 2013 14:23:56 -0800 Subject: [PATCH] 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 --- bin/disk-image-create | 14 ++-- elements/glance-api/element-deps | 1 + .../glance-api/first-boot.d/05-glance-api | 7 -- .../first-boot.d/etc_init_glance-api.conf | 9 --- elements/glance-api/install.d/05-glance-api | 32 +-------- elements/keystone/element-deps | 1 + elements/keystone/first-boot.d/05-keystone | 7 -- .../first-boot.d/etc_init_keystone.conf | 9 --- elements/keystone/install.d/05-keystone | 34 +--------- elements/nova-api/element-deps | 1 + elements/nova-api/install.d/05-nova-api | 36 +--------- elements/nova-api/upstart/nova-api.conf | 30 -------- elements/os-svc-install/README.md | 9 +++ .../install.d/04-os-svc-install | 7 ++ elements/os-svc-install/os-svc-install | 68 +++++++++++++++++++ lib/common-functions | 12 ++-- lib/img-defaults | 8 +-- lib/img-functions | 7 +- lib/ramdisk-functions | 4 +- 19 files changed, 115 insertions(+), 181 deletions(-) create mode 100644 elements/glance-api/element-deps delete mode 100755 elements/glance-api/first-boot.d/05-glance-api delete mode 100644 elements/glance-api/first-boot.d/etc_init_glance-api.conf create mode 100644 elements/keystone/element-deps delete mode 100755 elements/keystone/first-boot.d/05-keystone delete mode 100644 elements/keystone/first-boot.d/etc_init_keystone.conf create mode 100644 elements/nova-api/element-deps delete mode 100644 elements/nova-api/upstart/nova-api.conf create mode 100644 elements/os-svc-install/README.md create mode 100755 elements/os-svc-install/install.d/04-os-svc-install create mode 100755 elements/os-svc-install/os-svc-install diff --git a/bin/disk-image-create b/bin/disk-image-create index 0c2fd4056..3a3a5441b 100755 --- a/bin/disk-image-create +++ b/bin/disk-image-create @@ -2,13 +2,13 @@ # # Copyright 2012 Hewlett-Packard Development Company, L.P. # All Rights Reserved. -# +# # 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 @@ -29,7 +29,7 @@ source $_LIB/die function show_options () { echo "Options:" 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 " -u -- uncompressed; do not compress the image - larger but faster" 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 ? NBD_DEV=/dev/nbd0 -if [[ $(qemu-nbd --help | grep cache) == *writeback* ]] ; then +if [[ $(qemu-nbd --help | grep cache) == *writeback* ]] ; then CACHE="--cache=writeback" -else +else echo "Warning: qemu-nbd without --cache=writeback is /slow/." CACHE="" 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 IMAGE_BLOCK_DEVICE=$NBD_DEV eval_run_d block-device "IMAGE_BLOCK_DEVICE=" diff --git a/elements/glance-api/element-deps b/elements/glance-api/element-deps new file mode 100644 index 000000000..2167c86fb --- /dev/null +++ b/elements/glance-api/element-deps @@ -0,0 +1 @@ +os-svc-install diff --git a/elements/glance-api/first-boot.d/05-glance-api b/elements/glance-api/first-boot.d/05-glance-api deleted file mode 100755 index be52f4f07..000000000 --- a/elements/glance-api/first-boot.d/05-glance-api +++ /dev/null @@ -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 - diff --git a/elements/glance-api/first-boot.d/etc_init_glance-api.conf b/elements/glance-api/first-boot.d/etc_init_glance-api.conf deleted file mode 100644 index 62fbede23..000000000 --- a/elements/glance-api/first-boot.d/etc_init_glance-api.conf +++ /dev/null @@ -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" - diff --git a/elements/glance-api/install.d/05-glance-api b/elements/glance-api/install.d/05-glance-api index ea79fce27..0e29a7cb5 100755 --- a/elements/glance-api/install.d/05-glance-api +++ b/elements/glance-api/install.d/05-glance-api @@ -1,32 +1,4 @@ #!/bin/sh +set -eux -# install 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 +os-svc-install -n glance-api -u glance -r https://github.com/openstack/glance.git -c "/opt/stack/glance/bin/glance-api" diff --git a/elements/keystone/element-deps b/elements/keystone/element-deps new file mode 100644 index 000000000..2167c86fb --- /dev/null +++ b/elements/keystone/element-deps @@ -0,0 +1 @@ +os-svc-install diff --git a/elements/keystone/first-boot.d/05-keystone b/elements/keystone/first-boot.d/05-keystone deleted file mode 100755 index 674172718..000000000 --- a/elements/keystone/first-boot.d/05-keystone +++ /dev/null @@ -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 - diff --git a/elements/keystone/first-boot.d/etc_init_keystone.conf b/elements/keystone/first-boot.d/etc_init_keystone.conf deleted file mode 100644 index 188bfdd45..000000000 --- a/elements/keystone/first-boot.d/etc_init_keystone.conf +++ /dev/null @@ -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" - diff --git a/elements/keystone/install.d/05-keystone b/elements/keystone/install.d/05-keystone index 1d1992dc8..997323f1e 100755 --- a/elements/keystone/install.d/05-keystone +++ b/elements/keystone/install.d/05-keystone @@ -1,32 +1,4 @@ -#!/bin/sh - -# install keystone - -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 +#!/bin/bash +set -eux +os-svc-install -n keystone -u keystone -r https://github.com/openstack/keystone.git -c "/opt/stack/keystone/bin/keystone-all" diff --git a/elements/nova-api/element-deps b/elements/nova-api/element-deps new file mode 100644 index 000000000..2167c86fb --- /dev/null +++ b/elements/nova-api/element-deps @@ -0,0 +1 @@ +os-svc-install diff --git a/elements/nova-api/install.d/05-nova-api b/elements/nova-api/install.d/05-nova-api index fc61668de..54afdac78 100755 --- a/elements/nova-api/install.d/05-nova-api +++ b/elements/nova-api/install.d/05-nova-api @@ -1,39 +1,5 @@ #!/bin/sh set -eux -useradd -G admin -m nova -s /bin/false - -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 +os-svc-install -n nova-api -u nova -r https://github.com/openstack/nova.git -c "/opt/stack/nova/bin/nova-api" diff --git a/elements/nova-api/upstart/nova-api.conf b/elements/nova-api/upstart/nova-api.conf deleted file mode 100644 index 8a1576c38..000000000 --- a/elements/nova-api/upstart/nova-api.conf +++ /dev/null @@ -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 - diff --git a/elements/os-svc-install/README.md b/elements/os-svc-install/README.md new file mode 100644 index 000000000..c947a6165 --- /dev/null +++ b/elements/os-svc-install/README.md @@ -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` + diff --git a/elements/os-svc-install/install.d/04-os-svc-install b/elements/os-svc-install/install.d/04-os-svc-install new file mode 100755 index 000000000..aac3b3dda --- /dev/null +++ b/elements/os-svc-install/install.d/04-os-svc-install @@ -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 + diff --git a/elements/os-svc-install/os-svc-install b/elements/os-svc-install/os-svc-install new file mode 100755 index 000000000..8a1483a08 --- /dev/null +++ b/elements/os-svc-install/os-svc-install @@ -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 <>$TMP_MOUNT_PATH/init - fi + fi done # Add our final steps to /init