diskimage-builder/elements/os-svc-install/bin/os-svc-install
Tim Miller ea57869d3e Run all openstack services in virtualenvs:
Python package dependency conflicts have been observed
to occur for certain combinations of services at certain
revision.

Running all services in virtualenvs removes the issue.

Change-Id: I100817569b43a5af3427b0ae20cebdc7d55d03a5
2013-04-02 18:13:07 -07:00

89 lines
2 KiB
Bash
Executable file

#!/bin/bash
set -eux
pypi_mirror=http://pypi.openstack.org/
pip_install="pip install -i $pypi_mirror "
function python-install() {
local name=$1
local svc_root=$2
pushd /opt/stack/venvs
virtualenv --system-site-packages $name
popd
set +u
source /opt/stack/venvs/$name/bin/activate
set -u
[ -e $svc_root/tools/pip-requires ] && pip install -r $svc_root/tools/pip-requires
$pip_install $svc_root
set +u
deactivate
set -u
}
function install-os-service() {
local user=$1
local repo=$(echo $2 | sed 's/github.com/review.openstack.org/')
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
local git_dir="--git-dir $svc_root/.git"
if [ ! -e $svc_root ]; then
git clone --depth=1 -b $branch $repo $svc_root
python-install $user $svc_root
else
if ! git $git_dir remote -v | grep $repo; then
echo "ERROR: $svc_root exists and did not come from $repo"
exit 1
fi
actual_rev=$(git $git_dir show | head -1 | awk '{print $2}')
git $git_dir checkout $branch
expected_rev=$(git $git_dir show | head -1 | awk '{print $2}')
if [ "$expected_rev" != "$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"