Seperate install of services and start scripts:

This allows openstack services to be git/pip installed
without installing any startup scripts.

This is useful for keystone-db or nova-db elements, for
example, where the service must be installed to perform
database migration, but no service start scripts need
be installed.

Additionally, add a tool to create openstack sql databases.

Use openstack pypi mirror:

Use the openstack pypi mirror for openstack service
installation. It's much faster than pypi.org.

Also, pip install $svc_repo/tools/pip-requires first,
if it exists, which is required to pick up oslo.config.

Change-Id: I72751d4da59f8597d20aea2f27a9dfabe2f63a8f
This commit is contained in:
Tim Miller 2013-02-20 21:46:27 -08:00
parent 8346115bf9
commit 6cfd9681b7
7 changed files with 121 additions and 75 deletions

View File

@ -23,3 +23,4 @@ glance-manage db_sync
create-os-db ovs_quantum quantum $db_pass

View File

@ -0,0 +1,19 @@
#!/bin/bash
set -eu
function create_db {
local sql="
drop database if exists $1;
create database if not exists $1;
grant all on $1.* to '$2'@'localhost' identified by '$3';
grant all on $1.* to '$2'@'%' identified by '$3';
flush privileges;"
echo "$sql" | mysql
}
if [ $# -lt 3 ]; then
echo "Usage: os-db-create DB_NAME DB_USER DB_PASS"
exit 1
fi
create_db $*

View File

@ -0,0 +1,32 @@
#!/bin/bash
set -eu
function install_upstart {
local name=$1
local user=$2
local cmd=$3
shift; shift; shift
local args=$*
cat > /etc/init/$name.conf <<EOF
start on runlevel [2345]
stop on runlevel [016]
pre-start script
mkdir -p /var/run/$user
chown -R $user:$user /var/run/$user
end script
respawn
exec sudo -u $user $cmd $args
EOF
}
if [ $# -lt 4 ]; then
echo "Usage: os-svc-daemon DAEMON_NAME USER COMMAND [ARG[ARG[...]]]"
exit 1
fi
# TODO: check what system we are on, and install
# systemv instead, if appropriate.
install_upstart $*

View File

@ -0,0 +1,60 @@
#!/bin/bash
set -eux
pypi_mirror=http://pypi.openstack.org/
pip_install="pip install -i $pypi_mirror "
function install-os-service() {
local user=$1
local repo=$2
local branch=$3
id $user || useradd $user --system -d /var/run/$user -s /bin/false
mkdir -p /etc/$user
chown -R $user:$user /etc/$user
local svc_root=/opt/stack/$user
if [ ! -e $svc_root ]; then
git clone --depth=1 -b $branch $repo $svc_root
[ -e $svc_root/tools/pip-requires ] && $pip_install -r $svc_root/tools/pip-requires
$pip_install $svc_root
else
expected_rev=$(git --git-dir $svc_root/.git rev-parse $branch)
actual_rev=$(git --git-dir $svc_root/.git show | head -1 | awk '{print $2}')
if [ "$expected_rev" -ne "$actual_rev" ]; then
echo "ERROR: $repo exists and is not on rev $branch"
exit 1
fi
fi
}
function usage() {
echo "options:"
echo " -h show usage and exit"
echo " -r service's git repo url"
echo " -b repo branch or ref (default 'master')"
echo " -u name of the service run-as user"
exit 0
}
while getopts r:u:c:n:h:b: opt; do
case "$opt" in
u) user=$OPTARG;;
h) usage;;
r) repo=$OPTARG;;
b) branch=$OPTARG;;
\?) usage;;
esac
done
branch=${branch:-master}
if [[ -z "$user" || -z "$repo" ]]; 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 "$user" "$repo" "$branch"

View File

@ -1,7 +0,0 @@
#!/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

@ -1,68 +0,0 @@
#!/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

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