summaryrefslogtreecommitdiff
path: root/elements/os-svc-install
diff options
context:
space:
mode:
authorDan Prince <dprince@redhat.com>2014-02-27 14:36:59 -0500
committerDan Prince <dprince@redhat.com>2014-03-24 09:55:53 -0400
commit848f2b881bc8ad8647680f9ee8edf0bb31a7ea05 (patch)
tree9b06e21e81beabd5a12dc8ebb9f5754cb38c4c6f /elements/os-svc-install
parent54eafe8d89e4f7b52dab0ab5abd24675929b3469 (diff)
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
Notes
Notes (review): Verified+2: Jenkins Code-Review+2: Derek Higgins <derekh@redhat.com> Approved+1: James Slagle <jslagle@redhat.com> Code-Review+2: James Slagle <jslagle@redhat.com> Code-Review+1: Gregory Haynes <greg@greghaynes.net> Submitted-by: Jenkins Submitted-at: Mon, 24 Mar 2014 18:19:27 +0000 Reviewed-on: https://review.openstack.org/76952 Project: openstack/tripleo-image-elements Branch: refs/heads/master
Diffstat (limited to 'elements/os-svc-install')
-rw-r--r--elements/os-svc-install/README.md3
-rwxr-xr-xelements/os-svc-install/bin/os-svc-daemon32
-rwxr-xr-xelements/os-svc-install/bin/os-svc-install40
3 files changed, 49 insertions, 26 deletions
diff --git a/elements/os-svc-install/README.md b/elements/os-svc-install/README.md
index a5309fd..b7b6057 100644
--- a/elements/os-svc-install/README.md
+++ b/elements/os-svc-install/README.md
@@ -1,7 +1,8 @@
1Command line utilities to simplify installation of OpenStack services. 1Command line utilities to simplify installation of OpenStack services.
2 2
3## os-svc-install 3## os-svc-install
4Given a git repo url, pip-install the repo and all of its python dependencies into a virtualenv under /opt/stack/venvs. 4Given a git repo url, pip-install the repo and all of its python dependencies into a virtualenv.
5NOTE: By default the virtualenv is installed to /opt/stack/venvs/SERVICENAME but this can be customized.
5NOTE: By default services do not autostart until os-svc-enable is called. 6NOTE: By default services do not autostart until os-svc-enable is called.
6 7
7## os-svc-daemon 8## os-svc-daemon
diff --git a/elements/os-svc-install/bin/os-svc-daemon b/elements/os-svc-install/bin/os-svc-daemon
index 7181fc9..d3c9b71 100755
--- a/elements/os-svc-install/bin/os-svc-daemon
+++ b/elements/os-svc-install/bin/os-svc-daemon
@@ -18,6 +18,7 @@ usage() {
18 echo " default: $DEFAULT_POSTSTART" 18 echo " default: $DEFAULT_POSTSTART"
19 echo " -e ENV Environment name=value entries to set in the service/job" 19 echo " -e ENV Environment name=value entries to set in the service/job"
20 echo " -n SERVICENAME Name of job/service file." 20 echo " -n SERVICENAME Name of job/service file."
21 echo " -i INSTALLDIR Optional: virtualenv installation directory. Defaults to: /opt/stack/venvs/<SERVICENAME>"
21 echo " -u RUNAS User to run main executable as." 22 echo " -u RUNAS User to run main executable as."
22 echo " -c RUNCMD Command to execute. Must stay in foreground." 23 echo " -c RUNCMD Command to execute. Must stay in foreground."
23 echo " arg... Arguments will be passed to COMMAND" 24 echo " arg... Arguments will be passed to COMMAND"
@@ -26,6 +27,7 @@ usage() {
26 27
27# Can be set in environment now 28# Can be set in environment now
28SERVICENAME=${SERVICENAME:-""} 29SERVICENAME=${SERVICENAME:-""}
30INSTALLDIR=
29RUNAS=${RUNAS:-""} 31RUNAS=${RUNAS:-""}
30RUNCMD=${RUNCMD:-""} 32RUNCMD=${RUNCMD:-""}
31ENV=${ENV:-""} 33ENV=${ENV:-""}
@@ -44,9 +46,10 @@ print_to_file() {
44OUTPUT=print_to_file 46OUTPUT=print_to_file
45 47
46nshift=0 48nshift=0
47while getopts "phds:n:u:c:e:" opt; do 49while getopts "phds:n:i:u:c:e:" opt; do
48 case "$opt" in 50 case "$opt" in
49 n) SERVICENAME=$OPTARG;; 51 n) SERVICENAME=$OPTARG;;
52 i) INSTALLDIR=$OPTARG;;
50 u) RUNAS=$OPTARG;; 53 u) RUNAS=$OPTARG;;
51 c) RUNCMD=$OPTARG;; 54 c) RUNCMD=$OPTARG;;
52 s) POSTSTART=$OPTARG;; 55 s) POSTSTART=$OPTARG;;
@@ -72,12 +75,18 @@ fi
72[ -n "$RUNAS" ] || { RUNAS=$1 ; shift; } 75[ -n "$RUNAS" ] || { RUNAS=$1 ; shift; }
73[ -n "$RUNCMD" ] || { RUNCMD=$1 ; shift; } 76[ -n "$RUNCMD" ] || { RUNCMD=$1 ; shift; }
74 77
78# if INSTALLDIR isn't set use /opt/stack/venvs/RUNAS
79# NOTE: this was our default before adding the -i option
80if [ -z "$INSTALLDIR" ]; then
81 INSTALLDIR="/opt/stack/venvs/$RUNAS"
82fi
75 83
76function install_upstart { 84function install_upstart {
77 local name=$1 85 local name=$1
78 local user=$2 86 local install_dir=$2
79 local cmd=$3 87 local user=$3
80 shift; shift; shift 88 local cmd=$4
89 shift; shift; shift; shift;
81 local args=$* 90 local args=$*
82 91
83 local env_entries='' 92 local env_entries=''
@@ -105,7 +114,7 @@ respawn
105# not hit the default of 10 times in 5 seconds. Make it 2 times in 5s. 114# not hit the default of 10 times in 5 seconds. Make it 2 times in 5s.
106respawn limit 2 5 115respawn limit 2 5
107 116
108exec start-stop-daemon --start -c $user --exec /opt/stack/venvs/$user/bin/$cmd -- $args 117exec start-stop-daemon --start -c $user --exec $install_dir/bin/$cmd -- $args
109 118
110post-start $POSTSTART 119post-start $POSTSTART
111EOF 120EOF
@@ -113,9 +122,10 @@ EOF
113 122
114function install_systemd { 123function install_systemd {
115 local name=$1 124 local name=$1
116 local user=$2 125 local install_dir=$2
117 local cmd=$3 126 local user=$3
118 shift; shift; shift 127 local cmd=$4
128 shift; shift; shift; shift;
119 local args=$* 129 local args=$*
120 130
121 local env_entries='' 131 local env_entries=''
@@ -132,7 +142,7 @@ After=os-refresh-config.service
132Requires=$name-create-dir.service 142Requires=$name-create-dir.service
133 143
134[Service] 144[Service]
135ExecStart=/opt/stack/venvs/$user/bin/$cmd $args 145ExecStart=$install_dir/bin/$cmd $args
136User=$user 146User=$user
137$env_entries 147$env_entries
138 148
@@ -164,13 +174,13 @@ EOF
164# TODO: SysV init fallback support 174# TODO: SysV init fallback support
165DIB_INIT_SYSTEM=$(dib-init-system) 175DIB_INIT_SYSTEM=$(dib-init-system)
166if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then 176if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then
167 install_upstart $SERVICENAME $RUNAS $RUNCMD $* 177 install_upstart $SERVICENAME $INSTALLDIR $RUNAS $RUNCMD $*
168elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then 178elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then
169 if [ "$POSTSTART" != "$DEFAULT_POSTSTART" ] ; then 179 if [ "$POSTSTART" != "$DEFAULT_POSTSTART" ] ; then
170 echo "WARNING: post start is ignored with systemd." >&2 180 echo "WARNING: post start is ignored with systemd." >&2
171 fi 181 fi
172 if [ -z "$CREATE_DIR_ONLY" ]; then 182 if [ -z "$CREATE_DIR_ONLY" ]; then
173 install_systemd $SERVICENAME $RUNAS $RUNCMD $* 183 install_systemd $SERVICENAME $INSTALLDIR $RUNAS $RUNCMD $*
174 fi 184 fi
175 install_create_dir_systemd $SERVICENAME $RUNAS 185 install_create_dir_systemd $SERVICENAME $RUNAS
176fi 186fi
diff --git a/elements/os-svc-install/bin/os-svc-install b/elements/os-svc-install/bin/os-svc-install
index a0226cb..5a5e242 100755
--- a/elements/os-svc-install/bin/os-svc-install
+++ b/elements/os-svc-install/bin/os-svc-install
@@ -1,21 +1,20 @@
1#!/bin/bash 1#!/bin/bash
2set -eux 2set -eux
3 3
4function python-install() { 4function python_install() {
5 local name=$1 5 local svc_root=$1
6 local svc_root=$2 6 local install_dir=$2
7 local system_site_packages=${3:-"False"}
7 8
8 pushd /opt/stack/venvs
9 SITE_PCKGS="--no-site-packages" 9 SITE_PCKGS="--no-site-packages"
10 # Nova depends on python-libvirt which can't be installed via pip 10 if [ $system_site_packages == "True" ]; then
11 if [ $name == "nova" ]; then
12 SITE_PCKGS="--system-site-packages" 11 SITE_PCKGS="--system-site-packages"
13 fi 12 fi
14 virtualenv $SITE_PCKGS $name 13 mkdir -p $(dirname $install_dir)
15 popd 14 virtualenv $SITE_PCKGS $install_dir
16 15
17 set +u 16 set +u
18 source /opt/stack/venvs/$name/bin/activate 17 source $install_dir/bin/activate
19 set -u 18 set -u
20 19
21 if [ -e $svc_root/requirements.txt ]; then 20 if [ -e $svc_root/requirements.txt ]; then
@@ -46,10 +45,12 @@ function python-install() {
46} 45}
47 46
48 47
49function install-os-service() { 48function install_os_service() {
50 local user=$1 49 local user=$1
51 local repo=$(echo $2 | sed 's/github.com/review.openstack.org/') 50 local repo=$(echo $2 | sed 's/github.com/review.openstack.org/')
52 local branch=$3 51 local branch=$3
52 local directory=$4
53 local system_site_packages=$5
53 54
54 id $user || useradd $user --system -d /var/run/$user -s /bin/false 55 id $user || useradd $user --system -d /var/run/$user -s /bin/false
55 56
@@ -63,10 +64,10 @@ function install-os-service() {
63 # this would be the case when the source was retrieved by 64 # this would be the case when the source was retrieved by
64 # the source-repositories element 65 # the source-repositories element
65 if [ "${repo:0:1}" = "/" ] ; then 66 if [ "${repo:0:1}" = "/" ] ; then
66 python-install $user $repo 67 python_install $repo $directory $system_site_packages
67 elif [ ! -e $svc_root ]; then 68 elif [ ! -e $svc_root ]; then
68 git clone --depth=1 -b $branch $repo $svc_root 69 git clone --depth=1 -b $branch $repo $svc_root
69 python-install $user $svc_root 70 python_install $svc_root $directory $system_site_packages
70 else 71 else
71 if ! git $git_dir remote -v | grep $repo; then 72 if ! git $git_dir remote -v | grep $repo; then
72 echo "ERROR: $svc_root exists and did not come from $repo" 73 echo "ERROR: $svc_root exists and did not come from $repo"
@@ -88,17 +89,24 @@ function usage() {
88 echo " -h show usage and exit" 89 echo " -h show usage and exit"
89 echo " -r service's git repo url" 90 echo " -r service's git repo url"
90 echo " -b repo branch or ref (default 'master')" 91 echo " -b repo branch or ref (default 'master')"
92 echo " -i Optional: installation directory for the virtualenv."
93 echo " If not specified defaults to /opt/stack/venv/<service_name>."
91 echo " -u name of the service run-as user" 94 echo " -u name of the service run-as user"
95 echo " -s enable --system-site-packages in the virtualenv."
92} 96}
93 97
94user= 98user=
95repo= 99repo=
96while getopts hr:u:b: opt; do 100install_dir=
101system_site_packages="False"
102while getopts hsr:u:b:i: opt; do
97 case "$opt" in 103 case "$opt" in
98 u) user=$OPTARG;; 104 u) user=$OPTARG;;
105 i) install_dir=$OPTARG;;
99 h) usage; exit 0;; 106 h) usage; exit 0;;
100 r) repo=$OPTARG;; 107 r) repo=$OPTARG;;
101 b) branch=$OPTARG;; 108 b) branch=$OPTARG;;
109 s) system_site_packages="True";;
102 \?) usage; exit 1;; 110 \?) usage; exit 1;;
103 :) usage; exit 1;; 111 :) usage; exit 1;;
104 esac 112 esac
@@ -111,5 +119,9 @@ if [[ -z "$user" || -z "$repo" ]]; then
111 exit 1 119 exit 1
112fi 120fi
113 121
122if [[ -z "$install_dir" ]]; then
123 install_dir="/opt/stack/venvs/$user"
124fi
125
114install-packages python-dev git-core gcc libc6-dev libxml2-dev libxslt-dev libz-dev 126install-packages python-dev git-core gcc libc6-dev libxml2-dev libxslt-dev libz-dev
115install-os-service "$user" "$repo" "$branch" 127install_os_service "$user" "$repo" "$branch" "$install_dir" "$system_site_packages"