Browse Source

Merge "Allow os-svc-daemon to specify dir name with -d option"

Jenkins 5 years ago
parent
commit
c6e922197a

+ 1
- 1
elements/neutron-dhcp-agent/install.d/neutron-package-install/80-neutron-dhcp-agent View File

@@ -4,4 +4,4 @@ set -eux
4 4
 
5 5
 install-packages openstack-neutron
6 6
 
7
-os-svc-daemon -i "$NEUTRON_VENV_DIR" -n neutron-dhcp-agent -u neutron -c noop -d
7
+os-svc-daemon -i "$NEUTRON_VENV_DIR" -n neutron-dhcp-agent -u neutron

+ 1
- 1
elements/neutron-openvswitch-agent/install.d/neutron-package-install/80-neutron-openvswitch-agent View File

@@ -4,4 +4,4 @@ set -eux
4 4
 
5 5
 install-packages openstack-neutron-openvswitch
6 6
 
7
-os-svc-daemon -n neutron-openvswitch-agent -u neutron -c noop -d
7
+os-svc-daemon -n neutron-openvswitch-agent -u neutron

+ 1
- 1
elements/neutron-server/install.d/neutron-package-install/76-neutron View File

@@ -14,4 +14,4 @@ if [[ "RedHatEnterpriseServer CentOS Fedora" =~ "$DISTRO" ]]; then
14 14
     # https://bugzilla.redhat.com/show_bug.cgi?id=1057615
15 15
     rm -f /usr/lib/python2.7/site-packages/neutron-*.egg-info/requires.txt
16 16
 fi
17
-os-svc-daemon -i "$NEUTRON_VENV_DIR" -n neutron-server -u neutron -c noop -d
17
+os-svc-daemon -i "$NEUTRON_VENV_DIR" -n neutron-server -u neutron

+ 1
- 1
elements/nova-compute/install.d/nova-package-install/80-nova-compute View File

@@ -11,4 +11,4 @@ install-packages openstack-nova-compute
11 11
 rm -f /etc/libvirt/qemu/networks/autostart/default.xml
12 12
 rm -f /etc/libvirt/qemu/networks/default.xml
13 13
 
14
-os-svc-daemon -i "$NOVA_VENV_DIR" -n nova-compute -u nova -c noop -d
14
+os-svc-daemon -i "$NOVA_VENV_DIR" -n nova-compute -u nova

+ 36
- 20
elements/os-svc-install/bin/os-svc-daemon View File

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

Loading…
Cancel
Save