From 5fc2040aa5e8bb146b9b220ded376ca49a1995f9 Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Wed, 3 Dec 2014 12:13:39 -0800 Subject: [PATCH] Log directly to syslog from os services We currently have a horrible hack for upstart where we run our services with stdout and stderr piped into logger. There are lots of issues with this, such as upstart has a hard time knowing which PID to track. Conveniently, python logging knows how to syslog, so why not just use that! This changes the default behaviour of os-svc-daemon to create a python logging.conf so services log directly to syslog. This also changes the default upstart respawn limiting to be 2 fails in 10 secs. This is becauce making upstart monitor the actual service daemon was causing some services to respawn loop due to time it took them to fail. Closes-Bug: #1385346 Change-Id: Ibd491881d79160ad1457526d51512f5fc1cf9ea5 --- elements/os-svc-install/bin/os-svc-daemon | 49 +++++++++++++++++-- .../swift-source-install/76-swift-proxy | 2 +- .../swift-source-install/76-swift-storage | 26 +++++----- 3 files changed, 58 insertions(+), 19 deletions(-) diff --git a/elements/os-svc-install/bin/os-svc-daemon b/elements/os-svc-install/bin/os-svc-daemon index fd5ff0bd6..d232d7c31 100755 --- a/elements/os-svc-install/bin/os-svc-daemon +++ b/elements/os-svc-install/bin/os-svc-daemon @@ -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;; @@ -92,6 +96,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 <&1 | logger -t $name +exec start-stop-daemon --start -c $user --exec $install_dir/bin/$cmd -- $args post-start $POSTSTART EOF @@ -156,6 +191,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 <