Add -i options to os-svc-install/os-svc-daemon...

Update os-svc-install with a new -i option which can be used
to specify the virtualenv directory.

Update os-svc-install with a new -s option which can be used
to enable system-site-packages within the virtualenv. By
default this is disabled (matches virtualenv's default...)
In doing this we remove a hard coded check for the 'nova' service
by making nova use the -s option instead.

Update os-svc-daemon with a new -i option which can be used
to specify the virtualenv directory.

NOTE:
 I used -i for both os-svc-daemon and os-svc-install since it wasn't
 already used and I wanted to make the option the same in both places.

Change-Id: Ief53567711b0153de890d50a28c471b1e5acd56c
This commit is contained in:
Dan Prince 2014-02-27 14:36:59 -05:00
parent 54eafe8d89
commit 848f2b881b
4 changed files with 51 additions and 27 deletions

View File

@ -1,7 +1,8 @@
#!/bin/bash
set -eux
os-svc-install -u nova -r /opt/stack/nova
# -s enables system-site-packages explicitly for python-libvirt
os-svc-install -u nova -r /opt/stack/nova -s
cp /opt/stack/nova/etc/nova/policy.json /etc/nova/policy.json
cp /opt/stack/nova/etc/nova/api-paste.ini /etc/nova/api-paste.ini

View File

@ -1,7 +1,8 @@
Command line utilities to simplify installation of OpenStack services.
## os-svc-install
Given a git repo url, pip-install the repo and all of its python dependencies into a virtualenv under /opt/stack/venvs.
Given a git repo url, pip-install the repo and all of its python dependencies into a virtualenv.
NOTE: By default the virtualenv is installed to /opt/stack/venvs/SERVICENAME but this can be customized.
NOTE: By default services do not autostart until os-svc-enable is called.
## os-svc-daemon

View File

@ -18,6 +18,7 @@ usage() {
echo " default: $DEFAULT_POSTSTART"
echo " -e ENV Environment name=value entries to set in the service/job"
echo " -n SERVICENAME Name of job/service file."
echo " -i INSTALLDIR Optional: virtualenv installation directory. Defaults to: /opt/stack/venvs/<SERVICENAME>"
echo " -u RUNAS User to run main executable as."
echo " -c RUNCMD Command to execute. Must stay in foreground."
echo " arg... Arguments will be passed to COMMAND"
@ -26,6 +27,7 @@ usage() {
# Can be set in environment now
SERVICENAME=${SERVICENAME:-""}
INSTALLDIR=
RUNAS=${RUNAS:-""}
RUNCMD=${RUNCMD:-""}
ENV=${ENV:-""}
@ -44,9 +46,10 @@ print_to_file() {
OUTPUT=print_to_file
nshift=0
while getopts "phds:n:u:c:e:" opt; do
while getopts "phds:n:i:u:c:e:" opt; do
case "$opt" in
n) SERVICENAME=$OPTARG;;
i) INSTALLDIR=$OPTARG;;
u) RUNAS=$OPTARG;;
c) RUNCMD=$OPTARG;;
s) POSTSTART=$OPTARG;;
@ -72,12 +75,18 @@ fi
[ -n "$RUNAS" ] || { RUNAS=$1 ; shift; }
[ -n "$RUNCMD" ] || { RUNCMD=$1 ; shift; }
# if INSTALLDIR isn't set use /opt/stack/venvs/RUNAS
# NOTE: this was our default before adding the -i option
if [ -z "$INSTALLDIR" ]; then
INSTALLDIR="/opt/stack/venvs/$RUNAS"
fi
function install_upstart {
local name=$1
local user=$2
local cmd=$3
shift; shift; shift
local install_dir=$2
local user=$3
local cmd=$4
shift; shift; shift; shift;
local args=$*
local env_entries=''
@ -105,7 +114,7 @@ respawn
# not hit the default of 10 times in 5 seconds. Make it 2 times in 5s.
respawn limit 2 5
exec start-stop-daemon --start -c $user --exec /opt/stack/venvs/$user/bin/$cmd -- $args
exec start-stop-daemon --start -c $user --exec $install_dir/bin/$cmd -- $args
post-start $POSTSTART
EOF
@ -113,9 +122,10 @@ EOF
function install_systemd {
local name=$1
local user=$2
local cmd=$3
shift; shift; shift
local install_dir=$2
local user=$3
local cmd=$4
shift; shift; shift; shift;
local args=$*
local env_entries=''
@ -132,7 +142,7 @@ After=os-refresh-config.service
Requires=$name-create-dir.service
[Service]
ExecStart=/opt/stack/venvs/$user/bin/$cmd $args
ExecStart=$install_dir/bin/$cmd $args
User=$user
$env_entries
@ -164,13 +174,13 @@ EOF
# TODO: SysV init fallback support
DIB_INIT_SYSTEM=$(dib-init-system)
if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then
install_upstart $SERVICENAME $RUNAS $RUNCMD $*
install_upstart $SERVICENAME $INSTALLDIR $RUNAS $RUNCMD $*
elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then
if [ "$POSTSTART" != "$DEFAULT_POSTSTART" ] ; then
echo "WARNING: post start is ignored with systemd." >&2
fi
if [ -z "$CREATE_DIR_ONLY" ]; then
install_systemd $SERVICENAME $RUNAS $RUNCMD $*
install_systemd $SERVICENAME $INSTALLDIR $RUNAS $RUNCMD $*
fi
install_create_dir_systemd $SERVICENAME $RUNAS
fi

View File

@ -1,21 +1,20 @@
#!/bin/bash
set -eux
function python-install() {
local name=$1
local svc_root=$2
function python_install() {
local svc_root=$1
local install_dir=$2
local system_site_packages=${3:-"False"}
pushd /opt/stack/venvs
SITE_PCKGS="--no-site-packages"
# Nova depends on python-libvirt which can't be installed via pip
if [ $name == "nova" ]; then
if [ $system_site_packages == "True" ]; then
SITE_PCKGS="--system-site-packages"
fi
virtualenv $SITE_PCKGS $name
popd
mkdir -p $(dirname $install_dir)
virtualenv $SITE_PCKGS $install_dir
set +u
source /opt/stack/venvs/$name/bin/activate
source $install_dir/bin/activate
set -u
if [ -e $svc_root/requirements.txt ]; then
@ -46,10 +45,12 @@ function python-install() {
}
function install-os-service() {
function install_os_service() {
local user=$1
local repo=$(echo $2 | sed 's/github.com/review.openstack.org/')
local branch=$3
local directory=$4
local system_site_packages=$5
id $user || useradd $user --system -d /var/run/$user -s /bin/false
@ -63,10 +64,10 @@ function install-os-service() {
# this would be the case when the source was retrieved by
# the source-repositories element
if [ "${repo:0:1}" = "/" ] ; then
python-install $user $repo
python_install $repo $directory $system_site_packages
elif [ ! -e $svc_root ]; then
git clone --depth=1 -b $branch $repo $svc_root
python-install $user $svc_root
python_install $svc_root $directory $system_site_packages
else
if ! git $git_dir remote -v | grep $repo; then
echo "ERROR: $svc_root exists and did not come from $repo"
@ -88,17 +89,24 @@ function usage() {
echo " -h show usage and exit"
echo " -r service's git repo url"
echo " -b repo branch or ref (default 'master')"
echo " -i Optional: installation directory for the virtualenv."
echo " If not specified defaults to /opt/stack/venv/<service_name>."
echo " -u name of the service run-as user"
echo " -s enable --system-site-packages in the virtualenv."
}
user=
repo=
while getopts hr:u:b: opt; do
install_dir=
system_site_packages="False"
while getopts hsr:u:b:i: opt; do
case "$opt" in
u) user=$OPTARG;;
i) install_dir=$OPTARG;;
h) usage; exit 0;;
r) repo=$OPTARG;;
b) branch=$OPTARG;;
s) system_site_packages="True";;
\?) usage; exit 1;;
:) usage; exit 1;;
esac
@ -111,5 +119,9 @@ if [[ -z "$user" || -z "$repo" ]]; then
exit 1
fi
if [[ -z "$install_dir" ]]; then
install_dir="/opt/stack/venvs/$user"
fi
install-packages python-dev git-core gcc libc6-dev libxml2-dev libxslt-dev libz-dev
install-os-service "$user" "$repo" "$branch"
install_os_service "$user" "$repo" "$branch" "$install_dir" "$system_site_packages"