Merge "Log directly to syslog from os services"

This commit is contained in:
Jenkins 2015-01-05 17:29:44 +00:00 committed by Gerrit Code Review
commit a39ec21014
3 changed files with 58 additions and 19 deletions

View File

@ -8,11 +8,13 @@ usage() {
echo ""
echo "SERVICENAME, RUNAS, RUNCMD, and POSTSTART can be set via the"
echo "environment as well. Command line arguments will override"
echo "environment variables."
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."
@ -32,6 +34,7 @@ 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}
@ -53,7 +56,7 @@ OUTPUT=print_to_file
APPEND=append_to_file
nshift=0
while getopts "aphd:s:n:i:u:c:e:" opt; do
while getopts "aplhd:s:n:i:u:c:e:" opt; do
case "$opt" in
n) SERVICENAME=$OPTARG;;
i) INSTALLDIR=$OPTARG;;
@ -63,6 +66,7 @@ while getopts "aphd:s:n:i:u:c:e:" opt; do
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;;
@ -108,6 +112,33 @@ 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
@ -125,6 +156,10 @@ 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]
@ -144,13 +179,13 @@ 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 5s.
respawn limit 2 5
# not hit the default of 10 times in 5 seconds. Make it 2 times in 10s.
respawn limit 2 10
# We're logging to syslog
console none
exec start-stop-daemon --start -c $user --exec $install_dir/bin/$cmd -- $args 2>&1 | logger -t $name
exec start-stop-daemon --start -c $user --exec $install_dir/bin/$cmd -- $args
post-start $POSTSTART
EOF
@ -172,6 +207,10 @@ function install_systemd {
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

View File

@ -10,6 +10,6 @@ $SWIFT_VENV_DIR/bin/pip install keystonemiddleware
$SWIFT_VENV_DIR/bin/pip install python-swiftclient
$SWIFT_VENV_DIR/bin/pip install pycrypto
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-proxy swift swift-proxy-server "/etc/swift/proxy-server.conf"
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-proxy swift swift-proxy-server "/etc/swift/proxy-server.conf"
ln -s $SWIFT_VENV_DIR/bin/swift-recon /usr/local/bin/swift-recon

View File

@ -2,20 +2,20 @@
set -eux
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-account swift swift-account-server /etc/swift/account-server.conf
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-account-auditor swift swift-account-auditor /etc/swift/account-server.conf
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-account-reaper swift swift-account-reaper /etc/swift/account-server.conf
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-account-replicator swift swift-account-replicator /etc/swift/account-server.conf
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-account swift swift-account-server /etc/swift/account-server.conf
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-account-auditor swift swift-account-auditor /etc/swift/account-server.conf
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-account-reaper swift swift-account-reaper /etc/swift/account-server.conf
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-account-replicator swift swift-account-replicator /etc/swift/account-server.conf
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-container swift swift-container-server /etc/swift/container-server.conf
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-container-auditor swift swift-container-auditor /etc/swift/container-server.conf
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-container-replicator swift swift-container-replicator /etc/swift/container-server.conf
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-container-sync swift swift-container-sync /etc/swift/container-server.conf
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-container-updater swift swift-container-updater /etc/swift/container-server.conf
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-container swift swift-container-server /etc/swift/container-server.conf
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-container-auditor swift swift-container-auditor /etc/swift/container-server.conf
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-container-replicator swift swift-container-replicator /etc/swift/container-server.conf
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-container-sync swift swift-container-sync /etc/swift/container-server.conf
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-container-updater swift swift-container-updater /etc/swift/container-server.conf
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-object swift swift-object-server /etc/swift/object-server.conf
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-object-auditor swift swift-object-auditor /etc/swift/object-server.conf
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-object-replicator swift swift-object-replicator /etc/swift/object-server.conf
os-svc-daemon -i "$SWIFT_VENV_DIR" swift-object-updater swift swift-object-updater /etc/swift/object-server.conf
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-object swift swift-object-server /etc/swift/object-server.conf
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-object-auditor swift swift-object-auditor /etc/swift/object-server.conf
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-object-replicator swift swift-object-replicator /etc/swift/object-server.conf
os-svc-daemon -l -i "$SWIFT_VENV_DIR" swift-object-updater swift swift-object-updater /etc/swift/object-server.conf
ln -s $SWIFT_VENV_DIR/bin/swift-recon-cron /usr/local/bin/swift-recon-cron