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
This commit is contained in:
parent
e056d09840
commit
97f9fbed77
@ -4,4 +4,4 @@ set -eux
|
|||||||
|
|
||||||
install-packages openstack-neutron
|
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
|
||||||
|
@ -4,4 +4,4 @@ set -eux
|
|||||||
|
|
||||||
install-packages openstack-neutron-openvswitch
|
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
|
||||||
|
@ -14,4 +14,4 @@ if [[ "RedHatEnterpriseServer CentOS Fedora" =~ "$DISTRO" ]]; then
|
|||||||
# https://bugzilla.redhat.com/show_bug.cgi?id=1057615
|
# https://bugzilla.redhat.com/show_bug.cgi?id=1057615
|
||||||
rm -f /usr/lib/python2.7/site-packages/neutron-*.egg-info/requires.txt
|
rm -f /usr/lib/python2.7/site-packages/neutron-*.egg-info/requires.txt
|
||||||
fi
|
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
|
||||||
|
@ -11,4 +11,4 @@ install-packages openstack-nova-compute
|
|||||||
rm -f /etc/libvirt/qemu/networks/autostart/default.xml
|
rm -f /etc/libvirt/qemu/networks/autostart/default.xml
|
||||||
rm -f /etc/libvirt/qemu/networks/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
|
||||||
|
@ -4,7 +4,7 @@ set -eu
|
|||||||
DEFAULT_POSTSTART="exec sleep 1"
|
DEFAULT_POSTSTART="exec sleep 1"
|
||||||
|
|
||||||
usage() {
|
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 ""
|
||||||
echo "SERVICENAME, RUNAS, RUNCMD, and POSTSTART can be set via the"
|
echo "SERVICENAME, RUNAS, RUNCMD, and POSTSTART can be set via the"
|
||||||
echo "environment as well. Command line arguments will override"
|
echo "environment as well. Command line arguments will override"
|
||||||
@ -12,8 +12,8 @@ usage() {
|
|||||||
echo ""
|
echo ""
|
||||||
echo " -h Show help and exit"
|
echo " -h Show help and exit"
|
||||||
echo " -p Print the job file instead of writing to disk"
|
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 " -d [NAME] Specify the name of the runtime directory, which will be"
|
||||||
echo " not the actual systemd daemon service. Ignored for upstart."
|
echo " /var/run/[NAME]"
|
||||||
echo " -s POSTSTART post_start will be added to the upstart job. Ignored with systemd."
|
echo " -s POSTSTART post_start will be added to the upstart job. Ignored with systemd."
|
||||||
echo " default: $DEFAULT_POSTSTART"
|
echo " default: $DEFAULT_POSTSTART"
|
||||||
echo " -e ENV Environment name=value entries to set in the service/job"
|
echo " -e ENV Environment name=value entries to set in the service/job"
|
||||||
@ -31,7 +31,7 @@ INSTALLDIR=
|
|||||||
RUNAS=${RUNAS:-""}
|
RUNAS=${RUNAS:-""}
|
||||||
RUNCMD=${RUNCMD:-""}
|
RUNCMD=${RUNCMD:-""}
|
||||||
ENV=${ENV:-""}
|
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
|
# The default helps avoid race with daemon listening. http://pad.lv/1179766
|
||||||
POSTSTART=${POSTSTART:-$DEFAULT_POSTSTART}
|
POSTSTART=${POSTSTART:-$DEFAULT_POSTSTART}
|
||||||
|
|
||||||
@ -43,10 +43,15 @@ print_to_file() {
|
|||||||
cat > $1
|
cat > $1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
append_to_file() {
|
||||||
|
cat >> $1
|
||||||
|
}
|
||||||
|
|
||||||
OUTPUT=print_to_file
|
OUTPUT=print_to_file
|
||||||
|
APPEND=append_to_file
|
||||||
|
|
||||||
nshift=0
|
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
|
case "$opt" in
|
||||||
n) SERVICENAME=$OPTARG;;
|
n) SERVICENAME=$OPTARG;;
|
||||||
i) INSTALLDIR=$OPTARG;;
|
i) INSTALLDIR=$OPTARG;;
|
||||||
@ -54,8 +59,8 @@ while getopts "phds:n:i:u:c:e:" opt; do
|
|||||||
c) RUNCMD=$OPTARG;;
|
c) RUNCMD=$OPTARG;;
|
||||||
s) POSTSTART=$OPTARG;;
|
s) POSTSTART=$OPTARG;;
|
||||||
e) ENV=$OPTARG;;
|
e) ENV=$OPTARG;;
|
||||||
p) OUTPUT=print_only;;
|
p) OUTPUT=print_only; APPEND=print_only;;
|
||||||
d) CREATE_DIR_ONLY=1;;
|
d) CREATE_DIR_NAME=$OPTARG;;
|
||||||
h) usage; exit 0;;
|
h) usage; exit 0;;
|
||||||
\?) usage; exit 1;;
|
\?) usage; exit 1;;
|
||||||
:) usage; exit 1;;
|
:) usage; exit 1;;
|
||||||
@ -63,7 +68,7 @@ while getopts "phds:n:i:u:c:e:" opt; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
shift $(($OPTIND-1))
|
shift $(($OPTIND-1))
|
||||||
if [ -z "$SERVICENAME" ] || [ -z "$RUNAS" ] || [ -z "$RUNCMD" ] ; then
|
if [ -z "$SERVICENAME" ] || [ -z "$RUNAS" ] ; then
|
||||||
if [ $# -lt 3 ] ; then
|
if [ $# -lt 3 ] ; then
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
@ -73,7 +78,10 @@ fi
|
|||||||
# Compatibility with old style passing w/o switches
|
# Compatibility with old style passing w/o switches
|
||||||
[ -n "$SERVICENAME" ] || { SERVICENAME=$1 ; shift; }
|
[ -n "$SERVICENAME" ] || { SERVICENAME=$1 ; shift; }
|
||||||
[ -n "$RUNAS" ] || { RUNAS=$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
|
# if INSTALLDIR isn't set use /opt/stack/venvs/RUNAS
|
||||||
# NOTE: this was our default before adding the -i option
|
# NOTE: this was our default before adding the -i option
|
||||||
@ -85,8 +93,9 @@ function install_upstart {
|
|||||||
local name=$1
|
local name=$1
|
||||||
local install_dir=$2
|
local install_dir=$2
|
||||||
local user=$3
|
local user=$3
|
||||||
local cmd=$4
|
local dirname=${4:-$user}
|
||||||
shift; shift; shift; shift;
|
local cmd=$5
|
||||||
|
shift; shift; shift; shift; shift
|
||||||
local args=$*
|
local args=$*
|
||||||
|
|
||||||
local env_entries=''
|
local env_entries=''
|
||||||
@ -95,8 +104,9 @@ function install_upstart {
|
|||||||
env_entries=${env_pad// /
|
env_entries=${env_pad// /
|
||||||
env }
|
env }
|
||||||
fi
|
fi
|
||||||
|
local target_file="/etc/init/$name.conf"
|
||||||
|
|
||||||
$OUTPUT /etc/init/$name.conf <<EOF
|
$OUTPUT $target_file <<EOF
|
||||||
start on runlevel [2345]
|
start on runlevel [2345]
|
||||||
stop on runlevel [016]
|
stop on runlevel [016]
|
||||||
$env_entries
|
$env_entries
|
||||||
@ -105,9 +115,13 @@ env OS_SVC_ENABLE_CONTROL=1
|
|||||||
export OS_SVC_ENABLE_CONTROL
|
export OS_SVC_ENABLE_CONTROL
|
||||||
|
|
||||||
pre-start script
|
pre-start script
|
||||||
mkdir -p /var/run/$user
|
mkdir -p /var/run/$dirname
|
||||||
chown -R $user:$user /var/run/$user
|
chown -R $user:$user /var/run/$dirname
|
||||||
end script
|
end script
|
||||||
|
EOF
|
||||||
|
|
||||||
|
if [ -n "$cmd" ]; then
|
||||||
|
$APPEND $target_file <<EOF
|
||||||
|
|
||||||
respawn
|
respawn
|
||||||
# the default post-start of 1 second sleep delays respawning enough to
|
# 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
|
|||||||
|
|
||||||
post-start $POSTSTART
|
post-start $POSTSTART
|
||||||
EOF
|
EOF
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function install_systemd {
|
function install_systemd {
|
||||||
@ -156,14 +171,15 @@ EOF
|
|||||||
function install_create_dir_systemd {
|
function install_create_dir_systemd {
|
||||||
local name=$(map-services $1)
|
local name=$(map-services $1)
|
||||||
local user=$2
|
local user=$2
|
||||||
|
local dirname=${3:-$user}
|
||||||
|
|
||||||
$OUTPUT /usr/lib/systemd/system/$name-create-dir.service <<EOF
|
$OUTPUT /usr/lib/systemd/system/$name-create-dir.service <<EOF
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Create /var/run/$user
|
Description=Create /var/run/$dirname
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStartPre=/bin/mkdir -p /var/run/$user
|
ExecStartPre=/bin/mkdir -p /var/run/$dirname
|
||||||
ExecStart=/bin/chown -R $user:$user /var/run/$user
|
ExecStart=/bin/chown -R $user:$user /var/run/$dirname
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
RequiredBy=$name.service
|
RequiredBy=$name.service
|
||||||
@ -174,13 +190,13 @@ EOF
|
|||||||
# TODO: SysV init fallback support
|
# TODO: SysV init fallback support
|
||||||
DIB_INIT_SYSTEM=$(dib-init-system)
|
DIB_INIT_SYSTEM=$(dib-init-system)
|
||||||
if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then
|
if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then
|
||||||
install_upstart $SERVICENAME $INSTALLDIR $RUNAS $RUNCMD $*
|
install_upstart $SERVICENAME $INSTALLDIR $RUNAS "$CREATE_DIR_NAME" "$RUNCMD" $*
|
||||||
elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then
|
elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then
|
||||||
if [ "$POSTSTART" != "$DEFAULT_POSTSTART" ] ; then
|
if [ "$POSTSTART" != "$DEFAULT_POSTSTART" ] ; then
|
||||||
echo "WARNING: post start is ignored with systemd." >&2
|
echo "WARNING: post start is ignored with systemd." >&2
|
||||||
fi
|
fi
|
||||||
if [ -z "$CREATE_DIR_ONLY" ]; then
|
if [ -n "$RUNCMD" ]; then
|
||||||
install_systemd $SERVICENAME $INSTALLDIR $RUNAS $RUNCMD $*
|
install_systemd $SERVICENAME $INSTALLDIR $RUNAS $RUNCMD $*
|
||||||
fi
|
fi
|
||||||
install_create_dir_systemd $SERVICENAME $RUNAS
|
install_create_dir_systemd $SERVICENAME $RUNAS $CREATE_DIR_NAME
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user