summaryrefslogtreecommitdiff
path: root/elements/os-svc-install
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-03-27 14:58:27 +0000
committerGerrit Code Review <review@openstack.org>2014-03-27 14:58:27 +0000
commitc6e922197ab099581218558520d0b36959cf0b51 (patch)
tree9273f28fbaba2c4c1175b59dc5c3dab41cfab104 /elements/os-svc-install
parent199e6618bdbee8a4debcce628ee847eb4024834f (diff)
parent97f9fbed775bd327d8b9424f69901b39c775f65c (diff)
Merge "Allow os-svc-daemon to specify dir name with -d option"
Diffstat (limited to 'elements/os-svc-install')
-rwxr-xr-xelements/os-svc-install/bin/os-svc-daemon56
1 files changed, 36 insertions, 20 deletions
diff --git a/elements/os-svc-install/bin/os-svc-daemon b/elements/os-svc-install/bin/os-svc-daemon
index d3c9b71..3ed6ce8 100755
--- a/elements/os-svc-install/bin/os-svc-daemon
+++ b/elements/os-svc-install/bin/os-svc-daemon
@@ -4,7 +4,7 @@ set -eu
4DEFAULT_POSTSTART="exec sleep 1" 4DEFAULT_POSTSTART="exec sleep 1"
5 5
6usage() { 6usage() {
7 echo "Usage: os-svc-daemon [ -ph ] [ -s POSTSTART ] [ -e ENV ] -n SERVICENAME -u RUNAS -c RUNCMD -- [arg [arg...]]" 7 echo "Usage: os-svc-daemon [ -ph ] [ -s POSTSTART ] [ -e ENV ] -n SERVICENAME -u RUNAS [ -c RUNCMD -- [arg [arg...]]]"
8 echo "" 8 echo ""
9 echo "SERVICENAME, RUNAS, RUNCMD, and POSTSTART can be set via the" 9 echo "SERVICENAME, RUNAS, RUNCMD, and POSTSTART can be set via the"
10 echo "environment as well. Command line arguments will override" 10 echo "environment as well. Command line arguments will override"
@@ -12,8 +12,8 @@ usage() {
12 echo "" 12 echo ""
13 echo " -h Show help and exit" 13 echo " -h Show help and exit"
14 echo " -p Print the job file instead of writing to disk" 14 echo " -p Print the job file instead of writing to disk"
15 echo " -d Only create the systemd service that creates the run time directory," 15 echo " -d [NAME] Specify the name of the runtime directory, which will be"
16 echo " not the actual systemd daemon service. Ignored for upstart." 16 echo " /var/run/[NAME]"
17 echo " -s POSTSTART post_start will be added to the upstart job. Ignored with systemd." 17 echo " -s POSTSTART post_start will be added to the upstart job. Ignored with systemd."
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"
@@ -31,7 +31,7 @@ INSTALLDIR=
31RUNAS=${RUNAS:-""} 31RUNAS=${RUNAS:-""}
32RUNCMD=${RUNCMD:-""} 32RUNCMD=${RUNCMD:-""}
33ENV=${ENV:-""} 33ENV=${ENV:-""}
34CREATE_DIR_ONLY=${CREATE_DIR_ONLY:-""} 34CREATE_DIR_NAME=${CREATE_DIR_NAME:-""}
35# The default helps avoid race with daemon listening. http://pad.lv/1179766 35# The default helps avoid race with daemon listening. http://pad.lv/1179766
36POSTSTART=${POSTSTART:-$DEFAULT_POSTSTART} 36POSTSTART=${POSTSTART:-$DEFAULT_POSTSTART}
37 37
@@ -43,10 +43,15 @@ print_to_file() {
43 cat > $1 43 cat > $1
44} 44}
45 45
46append_to_file() {
47 cat >> $1
48}
49
46OUTPUT=print_to_file 50OUTPUT=print_to_file
51APPEND=append_to_file
47 52
48nshift=0 53nshift=0
49while getopts "phds:n:i:u:c:e:" opt; do 54while getopts "phd:s:n:i:u:c:e:" opt; do
50 case "$opt" in 55 case "$opt" in
51 n) SERVICENAME=$OPTARG;; 56 n) SERVICENAME=$OPTARG;;
52 i) INSTALLDIR=$OPTARG;; 57 i) INSTALLDIR=$OPTARG;;
@@ -54,8 +59,8 @@ while getopts "phds:n:i:u:c:e:" opt; do
54 c) RUNCMD=$OPTARG;; 59 c) RUNCMD=$OPTARG;;
55 s) POSTSTART=$OPTARG;; 60 s) POSTSTART=$OPTARG;;
56 e) ENV=$OPTARG;; 61 e) ENV=$OPTARG;;
57 p) OUTPUT=print_only;; 62 p) OUTPUT=print_only; APPEND=print_only;;
58 d) CREATE_DIR_ONLY=1;; 63 d) CREATE_DIR_NAME=$OPTARG;;
59 h) usage; exit 0;; 64 h) usage; exit 0;;
60 \?) usage; exit 1;; 65 \?) usage; exit 1;;
61 :) usage; exit 1;; 66 :) usage; exit 1;;
@@ -63,7 +68,7 @@ while getopts "phds:n:i:u:c:e:" opt; do
63done 68done
64 69
65shift $(($OPTIND-1)) 70shift $(($OPTIND-1))
66if [ -z "$SERVICENAME" ] || [ -z "$RUNAS" ] || [ -z "$RUNCMD" ] ; then 71if [ -z "$SERVICENAME" ] || [ -z "$RUNAS" ] ; then
67 if [ $# -lt 3 ] ; then 72 if [ $# -lt 3 ] ; then
68 usage 73 usage
69 exit 1 74 exit 1
@@ -73,7 +78,10 @@ fi
73# Compatibility with old style passing w/o switches 78# Compatibility with old style passing w/o switches
74[ -n "$SERVICENAME" ] || { SERVICENAME=$1 ; shift; } 79[ -n "$SERVICENAME" ] || { SERVICENAME=$1 ; shift; }
75[ -n "$RUNAS" ] || { RUNAS=$1 ; shift; } 80[ -n "$RUNAS" ] || { RUNAS=$1 ; shift; }
76[ -n "$RUNCMD" ] || { RUNCMD=$1 ; shift; } 81if [ -z "$RUNCMD" ]; then
82 CHECK=${1:-""}
83 [ -n "$CHECK" ] && { RUNCMD=$1 ; shift; }
84fi
77 85
78# if INSTALLDIR isn't set use /opt/stack/venvs/RUNAS 86# if INSTALLDIR isn't set use /opt/stack/venvs/RUNAS
79# NOTE: this was our default before adding the -i option 87# NOTE: this was our default before adding the -i option
@@ -85,8 +93,9 @@ function install_upstart {
85 local name=$1 93 local name=$1
86 local install_dir=$2 94 local install_dir=$2
87 local user=$3 95 local user=$3
88 local cmd=$4 96 local dirname=${4:-$user}
89 shift; shift; shift; shift; 97 local cmd=$5
98 shift; shift; shift; shift; shift
90 local args=$* 99 local args=$*
91 100
92 local env_entries='' 101 local env_entries=''
@@ -95,8 +104,9 @@ function install_upstart {
95 env_entries=${env_pad// / 104 env_entries=${env_pad// /
96env } 105env }
97 fi 106 fi
107 local target_file="/etc/init/$name.conf"
98 108
99 $OUTPUT /etc/init/$name.conf <<EOF 109 $OUTPUT $target_file <<EOF
100start on runlevel [2345] 110start on runlevel [2345]
101stop on runlevel [016] 111stop on runlevel [016]
102$env_entries 112$env_entries
@@ -105,9 +115,13 @@ env OS_SVC_ENABLE_CONTROL=1
105export OS_SVC_ENABLE_CONTROL 115export OS_SVC_ENABLE_CONTROL
106 116
107pre-start script 117pre-start script
108 mkdir -p /var/run/$user 118 mkdir -p /var/run/$dirname
109 chown -R $user:$user /var/run/$user 119 chown -R $user:$user /var/run/$dirname
110end script 120end script
121EOF
122
123 if [ -n "$cmd" ]; then
124 $APPEND $target_file <<EOF
111 125
112respawn 126respawn
113# the default post-start of 1 second sleep delays respawning enough to 127# the default post-start of 1 second sleep delays respawning enough to
@@ -118,6 +132,7 @@ exec start-stop-daemon --start -c $user --exec $install_dir/bin/$cmd -- $args
118 132
119post-start $POSTSTART 133post-start $POSTSTART
120EOF 134EOF
135 fi
121} 136}
122 137
123function install_systemd { 138function install_systemd {
@@ -156,14 +171,15 @@ EOF
156function install_create_dir_systemd { 171function install_create_dir_systemd {
157 local name=$(map-services $1) 172 local name=$(map-services $1)
158 local user=$2 173 local user=$2
174 local dirname=${3:-$user}
159 175
160 $OUTPUT /usr/lib/systemd/system/$name-create-dir.service <<EOF 176 $OUTPUT /usr/lib/systemd/system/$name-create-dir.service <<EOF
161[Unit] 177[Unit]
162Description=Create /var/run/$user 178Description=Create /var/run/$dirname
163 179
164[Service] 180[Service]
165ExecStartPre=/bin/mkdir -p /var/run/$user 181ExecStartPre=/bin/mkdir -p /var/run/$dirname
166ExecStart=/bin/chown -R $user:$user /var/run/$user 182ExecStart=/bin/chown -R $user:$user /var/run/$dirname
167 183
168[Install] 184[Install]
169RequiredBy=$name.service 185RequiredBy=$name.service
@@ -174,13 +190,13 @@ EOF
174# TODO: SysV init fallback support 190# TODO: SysV init fallback support
175DIB_INIT_SYSTEM=$(dib-init-system) 191DIB_INIT_SYSTEM=$(dib-init-system)
176if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then 192if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then
177 install_upstart $SERVICENAME $INSTALLDIR $RUNAS $RUNCMD $* 193 install_upstart $SERVICENAME $INSTALLDIR $RUNAS "$CREATE_DIR_NAME" "$RUNCMD" $*
178elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then 194elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then
179 if [ "$POSTSTART" != "$DEFAULT_POSTSTART" ] ; then 195 if [ "$POSTSTART" != "$DEFAULT_POSTSTART" ] ; then
180 echo "WARNING: post start is ignored with systemd." >&2 196 echo "WARNING: post start is ignored with systemd." >&2
181 fi 197 fi
182 if [ -z "$CREATE_DIR_ONLY" ]; then 198 if [ -n "$RUNCMD" ]; then
183 install_systemd $SERVICENAME $INSTALLDIR $RUNAS $RUNCMD $* 199 install_systemd $SERVICENAME $INSTALLDIR $RUNAS $RUNCMD $*
184 fi 200 fi
185 install_create_dir_systemd $SERVICENAME $RUNAS 201 install_create_dir_systemd $SERVICENAME $RUNAS $CREATE_DIR_NAME
186fi 202fi