From 97f9fbed775bd327d8b9424f69901b39c775f65c Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Tue, 4 Mar 2014 16:22:16 -0600 Subject: [PATCH] Allow os-svc-daemon to specify dir name with -d option In some circumstances we need to be able to create a /var/run directory without actually installing a service. This behavior was supported before, but these changes allow the user to specify the directory name and streamline the process by making -c an optional parameter instead of requiring a dummy value. It also makes this functionality available on upstart-based systems. The existing uses of -d had to be updated as well to reflect this new behavior. Change-Id: I34f33f2290eeefb5be82c0cf5198ae53d34332ce --- .../80-neutron-dhcp-agent | 2 +- .../80-neutron-openvswitch-agent | 2 +- .../neutron-package-install/76-neutron | 2 +- .../nova-package-install/80-nova-compute | 2 +- elements/os-svc-install/bin/os-svc-daemon | 56 ++++++++++++------- 5 files changed, 40 insertions(+), 24 deletions(-) diff --git a/elements/neutron-dhcp-agent/install.d/neutron-package-install/80-neutron-dhcp-agent b/elements/neutron-dhcp-agent/install.d/neutron-package-install/80-neutron-dhcp-agent index 580b1d18b..6b7f72461 100755 --- a/elements/neutron-dhcp-agent/install.d/neutron-package-install/80-neutron-dhcp-agent +++ b/elements/neutron-dhcp-agent/install.d/neutron-package-install/80-neutron-dhcp-agent @@ -4,4 +4,4 @@ set -eux install-packages openstack-neutron -os-svc-daemon -i "$NEUTRON_VENV_DIR" -n neutron-dhcp-agent -u neutron -c noop -d +os-svc-daemon -i "$NEUTRON_VENV_DIR" -n neutron-dhcp-agent -u neutron diff --git a/elements/neutron-openvswitch-agent/install.d/neutron-package-install/80-neutron-openvswitch-agent b/elements/neutron-openvswitch-agent/install.d/neutron-package-install/80-neutron-openvswitch-agent index 3c14c4201..d4a5792a4 100755 --- a/elements/neutron-openvswitch-agent/install.d/neutron-package-install/80-neutron-openvswitch-agent +++ b/elements/neutron-openvswitch-agent/install.d/neutron-package-install/80-neutron-openvswitch-agent @@ -4,4 +4,4 @@ set -eux install-packages openstack-neutron-openvswitch -os-svc-daemon -n neutron-openvswitch-agent -u neutron -c noop -d +os-svc-daemon -n neutron-openvswitch-agent -u neutron diff --git a/elements/neutron-server/install.d/neutron-package-install/76-neutron b/elements/neutron-server/install.d/neutron-package-install/76-neutron index fa09bbcec..a90fdbea9 100755 --- a/elements/neutron-server/install.d/neutron-package-install/76-neutron +++ b/elements/neutron-server/install.d/neutron-package-install/76-neutron @@ -14,4 +14,4 @@ if [[ "RedHatEnterpriseServer CentOS Fedora" =~ "$DISTRO" ]]; then # https://bugzilla.redhat.com/show_bug.cgi?id=1057615 rm -f /usr/lib/python2.7/site-packages/neutron-*.egg-info/requires.txt fi -os-svc-daemon -i "$NEUTRON_VENV_DIR" -n neutron-server -u neutron -c noop -d +os-svc-daemon -i "$NEUTRON_VENV_DIR" -n neutron-server -u neutron diff --git a/elements/nova-compute/install.d/nova-package-install/80-nova-compute b/elements/nova-compute/install.d/nova-package-install/80-nova-compute index 041d72f3f..ef8994e33 100755 --- a/elements/nova-compute/install.d/nova-package-install/80-nova-compute +++ b/elements/nova-compute/install.d/nova-package-install/80-nova-compute @@ -11,4 +11,4 @@ install-packages openstack-nova-compute rm -f /etc/libvirt/qemu/networks/autostart/default.xml rm -f /etc/libvirt/qemu/networks/default.xml -os-svc-daemon -i "$NOVA_VENV_DIR" -n nova-compute -u nova -c noop -d +os-svc-daemon -i "$NOVA_VENV_DIR" -n nova-compute -u nova diff --git a/elements/os-svc-install/bin/os-svc-daemon b/elements/os-svc-install/bin/os-svc-daemon index d3c9b7105..3ed6ce8a7 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 DEFAULT_POSTSTART="exec sleep 1" usage() { - echo "Usage: os-svc-daemon [ -ph ] [ -s POSTSTART ] [ -e ENV ] -n SERVICENAME -u RUNAS -c RUNCMD -- [arg [arg...]]" + echo "Usage: os-svc-daemon [ -ph ] [ -s POSTSTART ] [ -e ENV ] -n SERVICENAME -u RUNAS [ -c RUNCMD -- [arg [arg...]]]" echo "" echo "SERVICENAME, RUNAS, RUNCMD, and POSTSTART can be set via the" echo "environment as well. Command line arguments will override" @@ -12,8 +12,8 @@ usage() { echo "" echo " -h Show help and exit" echo " -p Print the job file instead of writing to disk" - echo " -d Only create the systemd service that creates the run time directory," - echo " not the actual systemd daemon service. Ignored for upstart." + echo " -d [NAME] Specify the name of the runtime directory, which will be" + echo " /var/run/[NAME]" echo " -s POSTSTART post_start will be added to the upstart job. Ignored with systemd." echo " default: $DEFAULT_POSTSTART" echo " -e ENV Environment name=value entries to set in the service/job" @@ -31,7 +31,7 @@ INSTALLDIR= RUNAS=${RUNAS:-""} RUNCMD=${RUNCMD:-""} ENV=${ENV:-""} -CREATE_DIR_ONLY=${CREATE_DIR_ONLY:-""} +CREATE_DIR_NAME=${CREATE_DIR_NAME:-""} # The default helps avoid race with daemon listening. http://pad.lv/1179766 POSTSTART=${POSTSTART:-$DEFAULT_POSTSTART} @@ -43,10 +43,15 @@ print_to_file() { cat > $1 } +append_to_file() { + cat >> $1 +} + OUTPUT=print_to_file +APPEND=append_to_file nshift=0 -while getopts "phds:n:i:u:c:e:" opt; do +while getopts "phd:s:n:i:u:c:e:" opt; do case "$opt" in n) SERVICENAME=$OPTARG;; i) INSTALLDIR=$OPTARG;; @@ -54,8 +59,8 @@ while getopts "phds:n:i:u:c:e:" opt; do c) RUNCMD=$OPTARG;; s) POSTSTART=$OPTARG;; e) ENV=$OPTARG;; - p) OUTPUT=print_only;; - d) CREATE_DIR_ONLY=1;; + p) OUTPUT=print_only; APPEND=print_only;; + d) CREATE_DIR_NAME=$OPTARG;; h) usage; exit 0;; \?) usage; exit 1;; :) usage; exit 1;; @@ -63,7 +68,7 @@ while getopts "phds:n:i:u:c:e:" opt; do done shift $(($OPTIND-1)) -if [ -z "$SERVICENAME" ] || [ -z "$RUNAS" ] || [ -z "$RUNCMD" ] ; then +if [ -z "$SERVICENAME" ] || [ -z "$RUNAS" ] ; then if [ $# -lt 3 ] ; then usage exit 1 @@ -73,7 +78,10 @@ fi # Compatibility with old style passing w/o switches [ -n "$SERVICENAME" ] || { SERVICENAME=$1 ; shift; } [ -n "$RUNAS" ] || { RUNAS=$1 ; shift; } -[ -n "$RUNCMD" ] || { RUNCMD=$1 ; shift; } +if [ -z "$RUNCMD" ]; then + CHECK=${1:-""} + [ -n "$CHECK" ] && { RUNCMD=$1 ; shift; } +fi # if INSTALLDIR isn't set use /opt/stack/venvs/RUNAS # NOTE: this was our default before adding the -i option @@ -85,8 +93,9 @@ function install_upstart { local name=$1 local install_dir=$2 local user=$3 - local cmd=$4 - shift; shift; shift; shift; + local dirname=${4:-$user} + local cmd=$5 + shift; shift; shift; shift; shift local args=$* local env_entries='' @@ -95,8 +104,9 @@ function install_upstart { env_entries=${env_pad// / env } fi + local target_file="/etc/init/$name.conf" - $OUTPUT /etc/init/$name.conf <&2 fi - if [ -z "$CREATE_DIR_ONLY" ]; then + if [ -n "$RUNCMD" ]; then install_systemd $SERVICENAME $INSTALLDIR $RUNAS $RUNCMD $* fi - install_create_dir_systemd $SERVICENAME $RUNAS + install_create_dir_systemd $SERVICENAME $RUNAS $CREATE_DIR_NAME fi