56e50ee5cf
Move common openstack service installation operations into a new script `os-svc-install`, which simplifies the elements for openstack services. Change-Id: Ied8ac3278e7fe8af76e24748ec4e598a84afa03c
68 lines
1.3 KiB
Bash
Executable file
68 lines
1.3 KiB
Bash
Executable file
#!/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"
|
|
|