Simplify openvswitch, remove os-svc-install
This change simplifies the openvswitch element to install the actual package and enable the actual service. The openvswitch element is the only one still using the os-svc-install element just to enable the service, so os-svc-install can be deleted now. Change-Id: I464f4e0b6b2943cfb89fa51da77d726b726edb3f
This commit is contained in:
parent
44abab621f
commit
f11aa938c1
|
@ -1,2 +1 @@
|
|||
os-svc-install
|
||||
package-installs
|
||||
|
|
|
@ -1,22 +1,4 @@
|
|||
#!/bin/bash
|
||||
set -eux
|
||||
|
||||
if [ "$DIB_INIT_SYSTEM" == "systemd" ] ; then
|
||||
os-svc-enable -n openvswitch-switch
|
||||
fi
|
||||
|
||||
if [ "$DIB_INIT_SYSTEM" == "upstart" ] ; then
|
||||
echo "start on starting cloud-init-nonet" >> /etc/init/openvswitch-switch.override
|
||||
if [ ! -f /etc/init/openvswitch-switch.conf ] ; then
|
||||
cat << 'EOF' > /etc/init/openvswitch-switch.conf
|
||||
# openvswitch-switch
|
||||
# the purpose of this job is
|
||||
# * start openvwitch-switch in upstart rather than SysV startup
|
||||
pre-start script
|
||||
export RUNLEVEL=2
|
||||
/etc/init.d/openvswitch-switch start
|
||||
end script
|
||||
post-stop exec /etc/init.d/openvswitch-switch stop
|
||||
EOF
|
||||
fi
|
||||
fi
|
||||
systemctl enable openvswitch
|
||||
|
|
|
@ -1 +1 @@
|
|||
openvswitch-switch_package:
|
||||
openvswitch
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
{
|
||||
"family": {
|
||||
"redhat": {
|
||||
"openvswitch-switch_package": "openvswitch"
|
||||
}
|
||||
},
|
||||
"default": {
|
||||
"openvswitch-switch_package": "openvswitch-switch"
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
Command line utilities to simplify installation of OpenStack services.
|
||||
|
||||
## os-svc-install
|
||||
Given a git repo url, pip-install the repo and all of its python dependencies into a virtualenv.
|
||||
NOTE: By default the virtualenv is installed to /opt/stack/venvs/SERVICENAME but this can be customized.
|
||||
NOTE: By default services do not autostart until os-svc-enable is called.
|
||||
|
||||
## os-svc-daemon
|
||||
Given a system service command line and run-as user, generate and install system service start script. See output of `os-svc-daemon -h` for online help.
|
||||
|
||||
## os-svc-enable
|
||||
Enable the given service name so it starts on boot.
|
||||
This is typically called in an os-refresh-config/post-configure.d script to
|
||||
enable a service once it has been fully configured.
|
||||
|
||||
## os-svc-enable-upstart (upstart distros only)
|
||||
Given an upstart job and an action, acts on the enabled or disabled state
|
||||
of jobs produced by os-svc-daemon. This requires the os-svc-enable upstart
|
||||
job which is installed by this element as well. There is also an action,
|
||||
'enabled', which allows checking whether or not a service is enabled;
|
||||
the command exits 0 if it is enabled, or 1 if it is not. A disabled
|
||||
service will not be started automatically nor can it be manually started.
|
||||
|
||||
## example usage
|
||||
```bash
|
||||
# clone nova, and install it and its dependencies to /opt/stack/venvs/nova
|
||||
os-svc-install -u nova -r https://opendev.org/openstack/nova.git
|
||||
|
||||
# install a system-start script for nova-api
|
||||
os-svc-daemon -e 'foo=bar bar=baz' -n nova-api -u nova -c /opt/stack/venvs/nova/bin/nova-api -- --config-dir /etc/nova
|
||||
|
||||
# enable nova-api so that it starts on boot
|
||||
os-svc-enable -n nova-api
|
||||
```
|
|
@ -1,93 +0,0 @@
|
|||
#!/usr/bin/env python3
|
||||
# dib-lint: disable=indent
|
||||
# Copyright 2012 Hewlett-Packard Development Company, L.P.
|
||||
# Copyright 2014 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import os
|
||||
import sys
|
||||
|
||||
# Manually maintained for brevity; consider making this compiled from
|
||||
# distromatch or other rich data sources.
|
||||
# TripleO service name on the left, Fedora/RHEL on the right.
|
||||
service_map = {
|
||||
'apache2': 'httpd',
|
||||
'ceilometer-api': 'openstack-ceilometer-api',
|
||||
'ceilometer-agent-central': 'openstack-ceilometer-central',
|
||||
'ceilometer-agent-compute': 'openstack-ceilometer-compute',
|
||||
'ceilometer-agent-notification': 'openstack-ceilometer-notification',
|
||||
'ceilometer-collector': 'openstack-ceilometer-collector',
|
||||
'cinder-api': 'openstack-cinder-api',
|
||||
'cinder-backup': 'openstack-cinder-backup',
|
||||
'cinder-scheduler': 'openstack-cinder-scheduler',
|
||||
'cinder-volume': 'openstack-cinder-volume',
|
||||
'glance-api': 'openstack-glance-api',
|
||||
'glance-reg': 'openstack-glance-registry',
|
||||
'heat-api': 'openstack-heat-api',
|
||||
'heat-api-cfn': 'openstack-heat-api-cfn',
|
||||
'heat-api-cloudwatch': 'openstack-heat-api-cloudwatch',
|
||||
'heat-engine': 'openstack-heat-engine',
|
||||
'ironic-api': 'openstack-ironic-api',
|
||||
'ironic-conductor': 'openstack-ironic-conductor',
|
||||
'keystone': 'openstack-keystone',
|
||||
'libvirt-bin': 'libvirtd',
|
||||
'mysql': ['mysqld', 'mariadb'],
|
||||
'nova-conductor': 'openstack-nova-conductor',
|
||||
'nova-api': 'openstack-nova-api',
|
||||
'nova-cert': 'openstack-nova-cert',
|
||||
'nova-scheduler': 'openstack-nova-scheduler',
|
||||
'nova-consoleauth': 'openstack-nova-consoleauth',
|
||||
'nova-compute': 'openstack-nova-compute',
|
||||
'nova-novncproxy': 'openstack-nova-novncproxy',
|
||||
'openvswitch-switch': 'openvswitch',
|
||||
'rsync': 'rsyncd',
|
||||
'swift-proxy': 'openstack-swift-proxy',
|
||||
'swift-account': 'openstack-swift-account',
|
||||
'swift-account-auditor': 'openstack-swift-account-auditor',
|
||||
'swift-account-reaper': 'openstack-swift-account-reaper',
|
||||
'swift-account-replicator': 'openstack-swift-account-replicator',
|
||||
'swift-container': 'openstack-swift-container',
|
||||
'swift-container-auditor': 'openstack-swift-container-auditor',
|
||||
'swift-container-replicator': 'openstack-swift-container-replicator',
|
||||
'swift-container-updater': 'openstack-swift-container-updater',
|
||||
'swift-object': 'openstack-swift-object',
|
||||
'swift-object-auditor': 'openstack-swift-object-auditor',
|
||||
'swift-object-replicator': 'openstack-swift-object-replicator',
|
||||
'swift-object-updater': 'openstack-swift-object-updater',
|
||||
'tgt': 'tgtd',
|
||||
}
|
||||
|
||||
print("WARNING: map-services has been deprecated. "
|
||||
"Please use the svc-map element.", file=sys.stderr)
|
||||
|
||||
for arg in sys.argv[1:]:
|
||||
# We need to support the service name being different when installing from
|
||||
# source vs. packages. So, if the requested service file already exists,
|
||||
# just use that.
|
||||
if os.path.exists('/lib/systemd/system/%s.service' % arg):
|
||||
print(arg)
|
||||
else:
|
||||
mapping = service_map.get(arg, arg)
|
||||
# Handle cases where a service may map to multiple names depending on
|
||||
# which specific distribution we're using.
|
||||
if isinstance(mapping, list):
|
||||
for name in mapping:
|
||||
if os.path.exists('/lib/systemd/system/%s.service' % name):
|
||||
print(name)
|
||||
break
|
||||
else:
|
||||
# We didn't find a match for any of the mappings.
|
||||
print(arg)
|
||||
else:
|
||||
print(mapping)
|
||||
sys.exit(0)
|
|
@ -1,18 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
function create_db() {
|
||||
local sql="
|
||||
create database if not exists $1;
|
||||
grant all on $1.* to '$2'@'localhost' identified by '$3';
|
||||
grant all on $1.* to '$2'@'%' identified by '$3';
|
||||
flush privileges;"
|
||||
echo "$sql" | mysql
|
||||
}
|
||||
|
||||
if [ $# -lt 3 ]; then
|
||||
echo "Usage: os-db-create DB_NAME DB_USER DB_PASS"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
create_db $*
|
|
@ -1,261 +0,0 @@
|
|||
#!/bin/bash
|
||||
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 ""
|
||||
echo "SERVICENAME, RUNAS, RUNCMD, and POSTSTART can be set via the"
|
||||
echo "environment as well. Command line arguments will override"
|
||||
echo "environment variables. By default this will create a python logging"
|
||||
echo "configuration file in /etc/os-logging/servicename.conf"
|
||||
echo ""
|
||||
echo " -a Use alternate svc-map instead of map-services"
|
||||
echo " -h Show help and exit"
|
||||
echo " -p Print the job file instead of writing to disk"
|
||||
echo " -l Create neither a python logging.conf nor pass --log-config-append argument to command."
|
||||
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"
|
||||
echo " -n SERVICENAME Name of job/service file."
|
||||
echo " -i INSTALLDIR Optional: virtualenv installation directory. Defaults to: /opt/stack/venvs/<SERVICENAME>"
|
||||
echo " -u RUNAS User to run main executable as."
|
||||
echo " -c RUNCMD Command to execute. Must stay in foreground."
|
||||
echo " arg... Arguments will be passed to COMMAND"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Can be set in environment now
|
||||
SERVICENAME=${SERVICENAME:-""}
|
||||
INSTALLDIR=
|
||||
RUNAS=${RUNAS:-""}
|
||||
RUNCMD=${RUNCMD:-""}
|
||||
ENV=${ENV:-""}
|
||||
DISABLE_LOGGING_CONF=
|
||||
CREATE_DIR_NAME=${CREATE_DIR_NAME:-""}
|
||||
# The default helps avoid race with daemon listening. http://pad.lv/1179766
|
||||
POSTSTART=${POSTSTART:-$DEFAULT_POSTSTART}
|
||||
MAPPING_COMMAND=map-services
|
||||
|
||||
print_only() {
|
||||
cat
|
||||
}
|
||||
|
||||
print_to_file() {
|
||||
cat > $1
|
||||
}
|
||||
|
||||
append_to_file() {
|
||||
cat >> $1
|
||||
}
|
||||
|
||||
OUTPUT=print_to_file
|
||||
APPEND=append_to_file
|
||||
|
||||
nshift=0
|
||||
while getopts "aplhd:s:n:i:u:c:e:" opt; do
|
||||
case "$opt" in
|
||||
n) SERVICENAME=$OPTARG;;
|
||||
i) INSTALLDIR=$OPTARG;;
|
||||
u) RUNAS=$OPTARG;;
|
||||
c) RUNCMD=$OPTARG;;
|
||||
s) POSTSTART=$OPTARG;;
|
||||
e) ENV=$OPTARG;;
|
||||
a) MAPPING_COMMAND=svc-map;;
|
||||
p) OUTPUT=print_only; APPEND=print_only;;
|
||||
l) DISABLE_LOGGING_CONF="1";;
|
||||
d) CREATE_DIR_NAME=$OPTARG;;
|
||||
h) usage; exit 0;;
|
||||
\?) usage; exit 1;;
|
||||
:) usage; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND-1))
|
||||
if [ -z "$SERVICENAME" ] || [ -z "$RUNAS" ] ; then
|
||||
if [ $# -lt 3 ] ; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
function deprecated_posarg_warning {
|
||||
echo "WARNING: Setting $1 via positional argument is deprecated and will be removed in a future release."
|
||||
}
|
||||
|
||||
# Compatibility with old style passing w/o switches
|
||||
if [ -z "$SERVICENAME" ]; then
|
||||
SERVICENAME=$1
|
||||
shift
|
||||
deprecated_posarg_warning "SERVICENAME"
|
||||
fi
|
||||
if [ -z "$RUNAS" ]; then
|
||||
RUNAS=$1
|
||||
shift
|
||||
deprecated_posarg_warning "RUNAS"
|
||||
fi
|
||||
if [ -z "$RUNCMD" ]; then
|
||||
CHECK=${1:-""}
|
||||
if [ -n "$CHECK" ]; then
|
||||
RUNCMD=$1
|
||||
shift
|
||||
deprecated_posarg_warning "CHECK"
|
||||
fi
|
||||
fi
|
||||
|
||||
# if INSTALLDIR isn't set use /opt/stack/venvs/RUNAS
|
||||
# NOTE: this was our default before adding the -i option
|
||||
if [ -z "$INSTALLDIR" ]; then
|
||||
INSTALLDIR="/opt/stack/venvs/$RUNAS"
|
||||
fi
|
||||
|
||||
if [ -z "$DISABLE_LOGGING_CONF" ]; then
|
||||
# Set up service-specific logging config
|
||||
LOGGING_CONFIG="/etc/os-logging/$SERVICENAME.config"
|
||||
mkdir /etc/os-logging || true
|
||||
$OUTPUT $LOGGING_CONFIG <<EOF
|
||||
[loggers]
|
||||
keys=root
|
||||
|
||||
[handlers]
|
||||
keys=syslog
|
||||
|
||||
[formatters]
|
||||
keys=normal
|
||||
|
||||
[logger_root]
|
||||
handlers=syslog
|
||||
|
||||
[handler_syslog]
|
||||
class=handlers.SysLogHandler
|
||||
args=('/dev/log', handlers.SysLogHandler.LOG_USER)
|
||||
formatter=normal
|
||||
|
||||
[formatter_normal]
|
||||
format=$SERVICENAME: %(asctime)s %(levelname)s %(message)s
|
||||
EOF
|
||||
fi
|
||||
|
||||
function install_upstart {
|
||||
local name=$1
|
||||
local install_dir=$2
|
||||
local user=$3
|
||||
local dirname=${4:-$user}
|
||||
local cmd=$5
|
||||
shift; shift; shift; shift; shift
|
||||
local args=$*
|
||||
|
||||
local env_entries=''
|
||||
if [ -n "$ENV" ]; then
|
||||
local env_pad=" $ENV"
|
||||
env_entries=${env_pad// /
|
||||
env }
|
||||
fi
|
||||
local target_file="/etc/init/$name.conf"
|
||||
|
||||
if [ -z "$DISABLE_LOGGING_CONF" ]; then
|
||||
args="--log-config-append $LOGGING_CONFIG $args"
|
||||
fi
|
||||
|
||||
$OUTPUT $target_file <<EOF
|
||||
start on runlevel [2345]
|
||||
stop on runlevel [016]
|
||||
$env_entries
|
||||
|
||||
env OS_SVC_ENABLE_CONTROL=1
|
||||
export OS_SVC_ENABLE_CONTROL
|
||||
|
||||
pre-start script
|
||||
mkdir -p /var/run/$dirname
|
||||
chown -R $user:$user /var/run/$dirname
|
||||
end script
|
||||
EOF
|
||||
|
||||
if [ -n "$cmd" ]; then
|
||||
$APPEND $target_file <<EOF
|
||||
|
||||
respawn
|
||||
# the default post-start of 1 second sleep delays respawning enough to
|
||||
# not hit the default of 10 times in 5 seconds. Make it 2 times in 10s.
|
||||
respawn limit 2 10
|
||||
|
||||
exec start-stop-daemon --start -c $user --exec $install_dir/bin/$cmd -- $args
|
||||
|
||||
post-start $POSTSTART
|
||||
EOF
|
||||
fi
|
||||
}
|
||||
|
||||
function install_systemd {
|
||||
local name=$1
|
||||
local install_dir=$2
|
||||
local user=$3
|
||||
local cmd=$4
|
||||
shift; shift; shift; shift;
|
||||
local args=$*
|
||||
|
||||
local env_entries=''
|
||||
if [ -n "$ENV" ]; then
|
||||
local env_pad=" $ENV"
|
||||
env_entries=${env_pad// /
|
||||
Environment=}
|
||||
fi
|
||||
|
||||
if [ -z "$DISABLE_LOGGING_CONF" ]; then
|
||||
args="--log-config-append $LOGGING_CONFIG $args"
|
||||
fi
|
||||
|
||||
$OUTPUT /lib/systemd/system/$name.service <<EOF
|
||||
[Unit]
|
||||
Description=$name Service
|
||||
After=os-refresh-config.service
|
||||
Requires=$name-create-dir.service
|
||||
|
||||
[Service]
|
||||
ExecStart=$install_dir/bin/$cmd $args
|
||||
User=$user
|
||||
$env_entries
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Alias=$name.service
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
function install_create_dir_systemd {
|
||||
local name="$($MAPPING_COMMAND "$1")"
|
||||
local user=$2
|
||||
local dirname=${3:-$user}
|
||||
|
||||
$OUTPUT /lib/systemd/system/$name-create-dir.service <<EOF
|
||||
[Unit]
|
||||
Description=Create /var/run/$dirname
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/bin/mkdir -p /var/run/$dirname
|
||||
ExecStartPre=/usr/local/bin/restore-selinux-file-context /var/run/$dirname
|
||||
ExecStart=/bin/chown -R $user:$user /var/run/$dirname
|
||||
|
||||
[Install]
|
||||
RequiredBy=$name.service
|
||||
EOF
|
||||
|
||||
}
|
||||
|
||||
# TODO: SysV init fallback support
|
||||
DIB_INIT_SYSTEM=$(dib-init-system)
|
||||
if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then
|
||||
install_upstart $SERVICENAME $INSTALLDIR $RUNAS "$CREATE_DIR_NAME" "$RUNCMD" $*
|
||||
elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then
|
||||
if [ "$POSTSTART" != "$DEFAULT_POSTSTART" ] ; then
|
||||
echo "WARNING: post start is ignored with systemd." >&2
|
||||
fi
|
||||
if [ -n "$RUNCMD" ]; then
|
||||
install_systemd $SERVICENAME $INSTALLDIR $RUNAS $RUNCMD $*
|
||||
fi
|
||||
install_create_dir_systemd $SERVICENAME $RUNAS $CREATE_DIR_NAME
|
||||
fi
|
|
@ -1,70 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2013 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
set -eu
|
||||
|
||||
usage() {
|
||||
echo "Usage: os-svc-enable -n SERVICENAME"
|
||||
echo ""
|
||||
echo " -a Use alternate svc-map instead of map-services"
|
||||
echo " -h Show help and exit"
|
||||
echo " -n SERVICENAME Name of job/service file."
|
||||
echo ""
|
||||
exit $1
|
||||
}
|
||||
|
||||
SERVICENAME=${SERVICENAME:-""}
|
||||
MAPPING_COMMAND=map-services
|
||||
|
||||
nshift=0
|
||||
while getopts "ahn:" opt; do
|
||||
case "$opt" in
|
||||
n) SERVICENAME=$OPTARG;;
|
||||
h) usage 0;;
|
||||
a) MAPPING_COMMAND=svc-map;;
|
||||
\?) usage 1;;
|
||||
:) usage 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND-1))
|
||||
if [ -z "$SERVICENAME" ] ; then
|
||||
usage 1
|
||||
fi
|
||||
|
||||
function enable_upstart_service() {
|
||||
local name="$1"
|
||||
os-svc-enable-upstart "$name" enable
|
||||
}
|
||||
|
||||
function enable_systemd_service() {
|
||||
local name="$1"
|
||||
local service_name="$($MAPPING_COMMAND "$name")"
|
||||
systemctl enable "$service_name.service"
|
||||
# Also enable the create-dir service if it exists
|
||||
if [ -f "/usr/lib/systemd/system/$service_name-create-dir.service" ]; then
|
||||
systemctl enable "$service_name-create-dir.service"
|
||||
fi
|
||||
}
|
||||
|
||||
# TODO: SysV init fallback support
|
||||
DIB_INIT_SYSTEM=$(dib-init-system)
|
||||
if [ "$DIB_INIT_SYSTEM" = "upstart" ]; then
|
||||
enable_upstart_service "$SERVICENAME"
|
||||
elif [ "$DIB_INIT_SYSTEM" = "systemd" ]; then
|
||||
enable_systemd_service "$SERVICENAME"
|
||||
fi
|
|
@ -1,81 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2013 Hewlett-Packard Development Company, L.P.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
set -eu
|
||||
|
||||
job_name=${1:-}
|
||||
action=${2:-}
|
||||
|
||||
function usage() {
|
||||
echo "usage: $(basename $0) job_name [enable|disable|enabled|clear]"
|
||||
}
|
||||
|
||||
if [ -z "$job_name" ] || [ -z "$action" ] ; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
OS_UPSTART_STATE_DIR=${OS_UPSTART_STATE_DIR:-/var/lib/os-svc-enable-upstart}
|
||||
|
||||
if [ "$action" != "enabled" ] ; then
|
||||
if ! [ -d "$OS_UPSTART_STATE_DIR" ] ; then
|
||||
if ! mkdir -p $OS_UPSTART_STATE_DIR ; then
|
||||
echo "ERROR: $OS_UPSTART_STATE_DIR does not exist or is not a directory."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! [ -w "$OS_UPSTART_STATE_DIR" ] ; then
|
||||
if ! chmod +w $OS_UPSTART_STATE_DIR ; then
|
||||
echo "ERROR: $OS_UPSTART_STATE_DIR is not writable."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ! -e "/etc/init/${job_name}.conf" ] ; then
|
||||
# Perhaps it's an init.d script.
|
||||
if [ "$action" = "enable" -a -e "/etc/init.d/$job_name" ]; then
|
||||
update-rc.d $job_name defaults 2>/dev/null
|
||||
exit 0
|
||||
else
|
||||
echo "WARNING: $job_name does not exist!"
|
||||
fi
|
||||
fi
|
||||
|
||||
enable_file="${OS_UPSTART_STATE_DIR}/${job_name}.enable"
|
||||
|
||||
case $action in
|
||||
clear)
|
||||
rm -f $enable_file
|
||||
;;
|
||||
enable)
|
||||
# Upstart jobs can have sub directories
|
||||
enable_file_home=$(dirname $enable_file)
|
||||
mkdir -p $enable_file_home
|
||||
touch $enable_file
|
||||
;;
|
||||
disable)
|
||||
rm -f $enable_file
|
||||
;;
|
||||
enabled)
|
||||
if [ -e "$enable_file" ] ; then
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
||||
;;
|
||||
esac
|
|
@ -1,149 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -eux
|
||||
|
||||
function python_install() {
|
||||
local svc_root=$1
|
||||
local install_dir=$2
|
||||
local system_site_packages=${3:-"False"}
|
||||
local name=$(basename $install_dir)
|
||||
local svc_manifest=$(get-pip-manifest $name)
|
||||
|
||||
SITE_PCKGS="--no-site-packages"
|
||||
if [ $system_site_packages == "True" ]; then
|
||||
SITE_PCKGS="--system-site-packages"
|
||||
fi
|
||||
mkdir -p $(dirname $install_dir)
|
||||
virtualenv $SITE_PCKGS $install_dir
|
||||
|
||||
set +u
|
||||
source $install_dir/bin/activate
|
||||
set -u
|
||||
|
||||
# If given an exact deps list, use it, and upgrade to the local git service
|
||||
if [ -n "$svc_manifest" ]; then
|
||||
use-pip-manifest $svc_manifest
|
||||
else
|
||||
if [ -e $svc_root/requirements.txt ]; then
|
||||
reqs=$svc_root/requirements.txt
|
||||
elif [ -e $svc_root/tools/pip-requires ]; then
|
||||
reqs=$svc_root/tools/pip-requires
|
||||
else
|
||||
reqs=""
|
||||
fi
|
||||
|
||||
# bug #1201253 : virtualenv-1.10.1 embeds setuptools-0.9.8, which
|
||||
# doesn't manage correctly HTTPS sockets when downloading pbr from
|
||||
# https://pypi.python.org/simple/ if using http_proxy and
|
||||
# https_proxy envvars
|
||||
pip install -U 'setuptools>=1.0'
|
||||
|
||||
# bug #1293812 : Avoid easy_install triggering on pbr.
|
||||
pip install -U 'pbr>=0.11'
|
||||
|
||||
if [ -n "$reqs" ] ; then
|
||||
# Install requirements off source repo if the install type
|
||||
# "source" has been specified and a cloned repo exists.
|
||||
for i in $(cat $reqs | grep -v ^# | grep -v ^$ | awk -F'[=><]' '{print $1}') ; do
|
||||
INSTALL_TYPE_VAR=DIB_INSTALLTYPE_${i//[^A-Za-z0-9]/_}
|
||||
INSTALL_TYPE=${!INSTALL_TYPE_VAR:-source}
|
||||
GIT_CLONE_DIR="/opt/stack/$i"
|
||||
if [ "$INSTALL_TYPE" = "source" ] && [ -d "$GIT_CLONE_DIR" ] ; then
|
||||
pip install $GIT_CLONE_DIR
|
||||
fi
|
||||
done
|
||||
|
||||
pip install -r $reqs
|
||||
fi
|
||||
fi
|
||||
# Always replay this, as we cannot use the entry this would generate in the manifest
|
||||
pip install $svc_root
|
||||
|
||||
# Write the manifest of what was installed
|
||||
write-pip-manifest $name
|
||||
|
||||
set +u
|
||||
deactivate
|
||||
set -u
|
||||
}
|
||||
|
||||
|
||||
function install_os_service() {
|
||||
local user=$1
|
||||
local repo=$(echo $2 | sed 's/github.com/review.opendev.org/')
|
||||
local branch=$3
|
||||
local directory=$4
|
||||
local system_site_packages=$5
|
||||
|
||||
id $user || useradd $user --system -d /var/run/$user -s /bin/false
|
||||
|
||||
install -d -m 0750 -o $user -g $user /etc/$user
|
||||
|
||||
local svc_root=/opt/stack/$user
|
||||
local git_dir="--git-dir $svc_root/.git"
|
||||
|
||||
# if the repository is an absolute local path then
|
||||
# we assume its present, on the correct branch and use it
|
||||
# this would be the case when the source was retrieved by
|
||||
# the source-repositories element
|
||||
if [ "${repo:0:1}" = "/" ] ; then
|
||||
python_install $repo $directory $system_site_packages
|
||||
elif [ ! -e $svc_root ]; then
|
||||
git clone --depth=1 -b $branch $repo $svc_root
|
||||
python_install $svc_root $directory $system_site_packages
|
||||
else
|
||||
if ! git $git_dir remote -v | grep $repo; then
|
||||
echo "ERROR: $svc_root exists and did not come from $repo"
|
||||
exit 1
|
||||
fi
|
||||
actual_rev=$(git $git_dir show | head -1 | awk '{print $2}')
|
||||
git $git_dir checkout $branch
|
||||
expected_rev=$(git $git_dir show | head -1 | awk '{print $2}')
|
||||
if [ "$expected_rev" != "$actual_rev" ]; then
|
||||
echo "ERROR: $repo exists and is not on rev $branch"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
function usage() {
|
||||
echo "options:"
|
||||
echo " -h show usage and exit"
|
||||
echo " -r service's git repo url"
|
||||
echo " -b repo branch or ref (default 'master')"
|
||||
echo " -i Optional: installation directory for the virtualenv."
|
||||
echo " If not specified defaults to /opt/stack/venv/<service_name>."
|
||||
echo " -u name of the service run-as user"
|
||||
echo " -s enable --system-site-packages in the virtualenv."
|
||||
}
|
||||
|
||||
user=
|
||||
repo=
|
||||
install_dir=
|
||||
system_site_packages="False"
|
||||
while getopts hsr:u:b:i: opt; do
|
||||
case "$opt" in
|
||||
u) user=$OPTARG;;
|
||||
i) install_dir=$OPTARG;;
|
||||
h) usage; exit 0;;
|
||||
r) repo=$OPTARG;;
|
||||
b) branch=$OPTARG;;
|
||||
s) system_site_packages="True";;
|
||||
\?) usage; exit 1;;
|
||||
:) usage; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
branch=${branch:-master}
|
||||
|
||||
if [[ -z "$user" || -z "$repo" ]]; then
|
||||
echo "missing required parameter"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -z "$install_dir" ]]; then
|
||||
install_dir="/opt/stack/venvs/$user"
|
||||
fi
|
||||
|
||||
install-packages python-dev git-core gcc libc6-dev libxml2-dev libxslt-dev libz-dev
|
||||
install_os_service "$user" "$repo" "$branch" "$install_dir" "$system_site_packages"
|
|
@ -1,65 +0,0 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Copyright 2013 Red Hat, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
set -eu
|
||||
|
||||
usage() {
|
||||
echo "Usage: os-svc-restart -n SERVICENAME"
|
||||
echo ""
|
||||
echo " -a Use alternate svc-map instead of map-services"
|
||||
echo " -h Show help and exit"
|
||||
echo " -n SERVICENAME Name of job/service file."
|
||||
echo ""
|
||||
exit $1
|
||||
}
|
||||
|
||||
SERVICENAME=${SERVICENAME:-""}
|
||||
MAPPING_COMMAND=map-services
|
||||
|
||||
nshift=0
|
||||
while getopts "ahn:" opt; do
|
||||
case "$opt" in
|
||||
n) SERVICENAME=$OPTARG;;
|
||||
h) usage 0;;
|
||||
a) MAPPING_COMMAND=svc-map;;
|
||||
\?) usage 0;;
|
||||
:) usage 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $(($OPTIND-1))
|
||||
if [ -z "$SERVICENAME" ] ; then
|
||||
usage 1
|
||||
fi
|
||||
|
||||
function restart_upstart_service {
|
||||
local name="$1"
|
||||
service "$name" restart
|
||||
}
|
||||
|
||||
function restart_systemd_service {
|
||||
local name="$1"
|
||||
systemctl restart "$($MAPPING_COMMAND "$name").service"
|
||||
}
|
||||
|
||||
# TODO: SysV init fallback support
|
||||
DIB_INIT_SYSTEM=$(dib-init-system)
|
||||
if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then
|
||||
restart_upstart_service "$SERVICENAME"
|
||||
elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then
|
||||
restart_systemd_service "$SERVICENAME"
|
||||
fi
|
|
@ -1,3 +0,0 @@
|
|||
pip-and-virtualenv
|
||||
pip-manifest
|
||||
svc-map
|
|
@ -1,16 +0,0 @@
|
|||
#!/bin/bash
|
||||
set -eux
|
||||
|
||||
install -m 0755 -o root -g root $(dirname $0)/../bin/os-svc-install /usr/local/bin/os-svc-install
|
||||
install -m 0755 -o root -g root $(dirname $0)/../bin/os-svc-daemon /usr/local/bin/os-svc-daemon
|
||||
install -m 0755 -o root -g root $(dirname $0)/../bin/os-db-create /usr/local/bin/os-db-create
|
||||
install -m 0755 -o root -g root $(dirname $0)/../bin/os-svc-enable /usr/local/bin/os-svc-enable
|
||||
install -m 0755 -o root -g root $(dirname $0)/../bin/map-services-tripleo /usr/local/bin/map-services
|
||||
|
||||
if [ "$(dib-init-system)" = "upstart" ] ; then
|
||||
install -m 0755 -o root -g root $(dirname $0)/../bin/os-svc-enable-upstart /usr/local/bin/os-svc-enable-upstart
|
||||
install -m 0644 -o root -g root $(dirname $0)/../upstart/os-svc-enable.conf /etc/init/os-svc-enable.conf
|
||||
install -m 0644 -o root -g root $(dirname $0)/../rsyslog.d/25-tripleo-apps.conf /etc/rsyslog.d/25-tripleo-apps.conf
|
||||
fi
|
||||
|
||||
install -m 0755 -o root -g root -d /opt/stack/venvs
|
|
@ -1,3 +0,0 @@
|
|||
# Log each app to its own log file
|
||||
$template tripleoAppLogFile,"/var/log/%programname%.log"
|
||||
user.notice ?tripleoAppLogFile
|
|
@ -1,225 +0,0 @@
|
|||
# Copyright 2014 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import tests.base
|
||||
|
||||
|
||||
class TestOsSvcDaemon(tests.base.ScriptTestBase):
|
||||
def setUp(self):
|
||||
super(TestOsSvcDaemon, self).setUp()
|
||||
self._stub_script('map-services', 'echo $1')
|
||||
|
||||
def test_standard_systemd(self):
|
||||
self._stub_script('dib-init-system', 'echo systemd')
|
||||
output = self._run_command(
|
||||
['elements/os-svc-install/bin/os-svc-daemon',
|
||||
'-l',
|
||||
'-p',
|
||||
'-n', 'foo',
|
||||
'-u', 'bar',
|
||||
'-c', 'baz', 'arg',
|
||||
])
|
||||
expected = """[Unit]
|
||||
Description=foo Service
|
||||
After=os-refresh-config.service
|
||||
Requires=foo-create-dir.service
|
||||
|
||||
[Service]
|
||||
ExecStart=/opt/stack/venvs/bar/bin/baz arg
|
||||
User=bar
|
||||
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Alias=foo.service
|
||||
[Unit]
|
||||
Description=Create /var/run/bar
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/bin/mkdir -p /var/run/bar
|
||||
ExecStartPre=/usr/local/bin/restore-selinux-file-context /var/run/bar
|
||||
ExecStart=/bin/chown -R bar:bar /var/run/bar
|
||||
|
||||
[Install]
|
||||
RequiredBy=foo.service
|
||||
"""
|
||||
self.assertEqual(expected, output)
|
||||
|
||||
def test_standard_upstart(self):
|
||||
self._stub_script('dib-init-system', 'echo upstart')
|
||||
output = self._run_command(
|
||||
['elements/os-svc-install/bin/os-svc-daemon',
|
||||
'-l',
|
||||
'-p',
|
||||
'-n', 'foo',
|
||||
'-u', 'bar',
|
||||
'-c', 'baz', 'a',
|
||||
])
|
||||
expected = """start on runlevel [2345]
|
||||
stop on runlevel [016]
|
||||
|
||||
|
||||
env OS_SVC_ENABLE_CONTROL=1
|
||||
export OS_SVC_ENABLE_CONTROL
|
||||
|
||||
pre-start script
|
||||
mkdir -p /var/run/bar
|
||||
chown -R bar:bar /var/run/bar
|
||||
end script
|
||||
|
||||
respawn
|
||||
# the default post-start of 1 second sleep delays respawning enough to
|
||||
# not hit the default of 10 times in 5 seconds. Make it 2 times in 10s.
|
||||
respawn limit 2 10
|
||||
|
||||
exec start-stop-daemon --start -c bar --exec /opt/stack/venvs/bar/bin/baz -- a
|
||||
|
||||
post-start exec sleep 1
|
||||
"""
|
||||
self.assertEqual(expected, output)
|
||||
|
||||
def test_dir_only_systemd(self):
|
||||
self._stub_script('dib-init-system', 'echo systemd')
|
||||
output = self._run_command(
|
||||
['elements/os-svc-install/bin/os-svc-daemon',
|
||||
'-l',
|
||||
'-p',
|
||||
'-n', 'foo',
|
||||
'-u', 'bar',
|
||||
])
|
||||
expected = """[Unit]
|
||||
Description=Create /var/run/bar
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/bin/mkdir -p /var/run/bar
|
||||
ExecStartPre=/usr/local/bin/restore-selinux-file-context /var/run/bar
|
||||
ExecStart=/bin/chown -R bar:bar /var/run/bar
|
||||
|
||||
[Install]
|
||||
RequiredBy=foo.service
|
||||
"""
|
||||
self.assertEqual(expected, output)
|
||||
|
||||
def test_dir_only_upstart(self):
|
||||
self._stub_script('dib-init-system', 'echo upstart')
|
||||
output = self._run_command(
|
||||
['elements/os-svc-install/bin/os-svc-daemon',
|
||||
'-l',
|
||||
'-p',
|
||||
'-n', 'foo',
|
||||
'-u', 'bar',
|
||||
])
|
||||
expected = """start on runlevel [2345]
|
||||
stop on runlevel [016]
|
||||
|
||||
|
||||
env OS_SVC_ENABLE_CONTROL=1
|
||||
export OS_SVC_ENABLE_CONTROL
|
||||
|
||||
pre-start script
|
||||
mkdir -p /var/run/bar
|
||||
chown -R bar:bar /var/run/bar
|
||||
end script
|
||||
"""
|
||||
self.assertEqual(expected, output)
|
||||
|
||||
def test_install_dir_systemd(self):
|
||||
self._stub_script('dib-init-system', 'echo systemd')
|
||||
output = self._run_command(
|
||||
['elements/os-svc-install/bin/os-svc-daemon',
|
||||
'-l',
|
||||
'-p',
|
||||
'-n', 'foo',
|
||||
'-u', 'foo',
|
||||
'-i', '/test/dir',
|
||||
'-c', 'foo', 'arg',
|
||||
])
|
||||
self.assertIn('ExecStart=/test/dir/bin/foo arg', output)
|
||||
|
||||
def test_install_dir_upstart(self):
|
||||
self._stub_script('dib-init-system', 'echo upstart')
|
||||
output = self._run_command(
|
||||
['elements/os-svc-install/bin/os-svc-daemon',
|
||||
'-l',
|
||||
'-p',
|
||||
'-n', 'foo',
|
||||
'-u', 'foo',
|
||||
'-i', '/test/dir',
|
||||
'-c', 'foo', 'arg',
|
||||
])
|
||||
self.assertIn('--exec /test/dir/bin/foo -- arg', output)
|
||||
|
||||
def test_environment_systemd(self):
|
||||
self._stub_script('dib-init-system', 'echo systemd')
|
||||
output = self._run_command(
|
||||
['elements/os-svc-install/bin/os-svc-daemon',
|
||||
'-p',
|
||||
'-n', 'foo',
|
||||
'-u', 'foo',
|
||||
'-e', '"foo=bar"',
|
||||
'-c', 'foo', 'arg',
|
||||
])
|
||||
self.assertIn('Environment="foo=bar"', output)
|
||||
|
||||
def test_environment_upstart(self):
|
||||
self._stub_script('dib-init-system', 'echo upstart')
|
||||
output = self._run_command(
|
||||
['elements/os-svc-install/bin/os-svc-daemon',
|
||||
'-p',
|
||||
'-l',
|
||||
'-n', 'foo',
|
||||
'-u', 'foo',
|
||||
'-e', 'foo=bar',
|
||||
'-c', 'foo', 'arg',
|
||||
])
|
||||
self.assertIn('env foo=bar', output)
|
||||
|
||||
def test_post_start_upstart(self):
|
||||
self._stub_script('dib-init-system', 'echo upstart')
|
||||
output = self._run_command(
|
||||
['elements/os-svc-install/bin/os-svc-daemon',
|
||||
'-l',
|
||||
'-p',
|
||||
'-n', 'foo',
|
||||
'-u', 'foo',
|
||||
'-s', 'bar',
|
||||
'-c', 'foo', 'arg',
|
||||
])
|
||||
self.assertIn('post-start bar', output)
|
||||
|
||||
def test_runtime_dir_systemd(self):
|
||||
self._stub_script('dib-init-system', 'echo systemd')
|
||||
output = self._run_command(
|
||||
['elements/os-svc-install/bin/os-svc-daemon',
|
||||
'-p',
|
||||
'-n', 'foo',
|
||||
'-u', 'bar',
|
||||
'-d', 'baz',
|
||||
'-c', 'foo', 'arg',
|
||||
])
|
||||
self.assertIn('ExecStartPre=/bin/mkdir -p /var/run/baz', output)
|
||||
self.assertIn('ExecStart=/bin/chown -R bar:bar /var/run/baz', output)
|
||||
|
||||
def test_runtime_dir_upstart(self):
|
||||
self._stub_script('dib-init-system', 'echo upstart')
|
||||
output = self._run_command(
|
||||
['elements/os-svc-install/bin/os-svc-daemon',
|
||||
'-p',
|
||||
'-n', 'foo',
|
||||
'-u', 'bar',
|
||||
'-d', 'baz',
|
||||
'-c', 'foo', 'arg',
|
||||
])
|
||||
self.assertIn('mkdir -p /var/run/baz', output)
|
||||
self.assertIn('chown -R bar:bar /var/run/baz', output)
|
|
@ -1,11 +0,0 @@
|
|||
description "TripleO Service Control Job"
|
||||
start on starting OS_SVC_ENABLE_CONTROL=1
|
||||
instance $JOB
|
||||
task
|
||||
console none
|
||||
script
|
||||
# --no-wait is extremely important as $JOB is already blocked on
|
||||
# this job. Thus the change to the stop goal will be delayed until
|
||||
# this job exits.
|
||||
os-svc-enable-upstart $JOB enabled || exec stop --no-wait $JOB
|
||||
end script
|
Loading…
Reference in New Issue