From 22c76841cb9a890e537c81c41cee373e8f5e645a Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Thu, 21 Dec 2017 13:17:36 -0800 Subject: [PATCH] Add support for zuul-fingergw This is a new service which centrally proxies log streaming. Change-Id: I1129be61c0a77dbd46e402204ea8c4da2889b016 --- files/fingergw-logging.conf | 49 +++++++++++++ files/zuul-fingergw.init | 141 ++++++++++++++++++++++++++++++++++++ manifests/fingergw.pp | 70 ++++++++++++++++++ 3 files changed, 260 insertions(+) create mode 100644 files/fingergw-logging.conf create mode 100644 files/zuul-fingergw.init create mode 100644 manifests/fingergw.pp diff --git a/files/fingergw-logging.conf b/files/fingergw-logging.conf new file mode 100644 index 0000000..aefbf9e --- /dev/null +++ b/files/fingergw-logging.conf @@ -0,0 +1,49 @@ +[loggers] +keys=root,zuul,gerrit,gear + +[handlers] +keys=console,debug,normal + +[formatters] +keys=simple + +[logger_root] +level=WARNING +handlers=console + +[logger_zuul] +level=DEBUG +handlers=debug,normal +qualname=zuul + +[logger_gerrit] +level=INFO +handlers=debug,normal +qualname=gerrit + +[logger_gear] +level=WARNING +handlers=debug,normal +qualname=gear + +[handler_console] +level=WARNING +class=StreamHandler +formatter=simple +args=(sys.stdout,) + +[handler_debug] +level=DEBUG +class=logging.handlers.WatchedFileHandler +formatter=simple +args=('/var/log/zuul/fingergw-debug.log',) + +[handler_normal] +level=INFO +class=logging.handlers.WatchedFileHandler +formatter=simple +args=('/var/log/zuul/fingergw.log',) + +[formatter_simple] +format=%(asctime)s %(levelname)s %(name)s: %(message)s +datefmt= diff --git a/files/zuul-fingergw.init b/files/zuul-fingergw.init new file mode 100644 index 0000000..080cae2 --- /dev/null +++ b/files/zuul-fingergw.init @@ -0,0 +1,141 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: zuul-fingergw +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Zuul +# Description: Zuul Executor +### END INIT INFO + +# Do NOT "set -e" + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin +DESC="Zuul Fingergw" +NAME=zuul-fingergw +DAEMON=/usr/local/bin/zuul-fingergw +PIDFILE=/var/run/$NAME/$NAME.pid +SCRIPTNAME=/etc/init.d/$NAME +USER=root + +# Exit if the package is not installed +[ -x "$DAEMON" ] || exit 0 + +# Read configuration variable file if it is present +[ -r /etc/default/$NAME ] && . /etc/default/$NAME + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.0-6) to ensure that this file is present. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + # Return + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + # 3 if pid file already exist + + mkdir -p /var/run/$NAME + chown $USER /var/run/$NAME + ulimit -n 8192 + if [ -f $PIDFILE ]; then + return 3 + fi + start-stop-daemon \ + --start --quiet --pidfile $PIDFILE -c $USER \ + --exec $DAEMON --test > /dev/null || return 1 + start-stop-daemon \ + --start --quiet --pidfile $PIDFILE -c $USER \ + --exec $DAEMON -- $DAEMON_ARGS || return 2 + # Add code here, if necessary, that waits for the process to be ready + # to handle requests from services started subsequently which depend + # on this one. As a last resort, sleep for some time. +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + start-stop-daemon --stop --signal 9 --pidfile $PIDFILE + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + rm -f /var/run/$NAME/* + return "$RETVAL" +} + +# +# Function that sends a SIGHUP to the daemon/service +# +do_reload() { + # + # If the daemon can reload its configuration without + # restarting (for example, when it is sent a SIGHUP), + # then implement that here. + # + start-stop-daemon \ + --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME + return 0 +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + 3) echo "Pidfile at $PIDFILE already exists, run service zuul-fingergw stop to clean up." + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + status) + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + reload|force-reload) + # + # If do_reload() is not implemented then leave this commented out + # and leave 'force-reload' as an alias for 'restart'. + # + log_daemon_msg "Reloading $DESC" "$NAME" + do_reload + log_end_msg $? + ;; + restart) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + do_start + ;; + *) + #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 + exit 3 + ;; +esac + +: diff --git a/manifests/fingergw.pp b/manifests/fingergw.pp new file mode 100644 index 0000000..1ce0d84 --- /dev/null +++ b/manifests/fingergw.pp @@ -0,0 +1,70 @@ +# Copyright 2017 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. + +# == Class: zuul::fingergw +# +class zuul::fingergw ( + $ensure = undef, + $manage_log_conf = true, +) { + + service { 'zuul-fingergw': + ensure => $ensure, + name => 'zuul-fingergw', + enable => true, + hasrestart => true, + require => [File['/etc/init.d/zuul-fingergw'], + Class['zuul::systemd_reload']] + } + + file { '/etc/init.d/zuul-fingergw': + ensure => present, + owner => 'root', + group => 'root', + mode => '0555', + source => 'puppet:///modules/zuul/zuul-fingergw.init', + notify => Class['zuul::systemd_reload'], + } + + if $manage_log_conf { + file { '/etc/zuul/fingergw-logging.conf': + ensure => present, + source => 'puppet:///modules/zuul/fingergw-logging.conf', + } + } + + include ::logrotate + ::logrotate::file { 'fingergw.log': + log => '/var/log/zuul/fingergw.log', + options => [ + 'compress', + 'missingok', + 'rotate 30', + 'daily', + 'notifempty', + ], + require => Service['zuul-fingergw'], + } + ::logrotate::file { 'fingergw-debug.log': + log => '/var/log/zuul/fingergw-debug.log', + options => [ + 'compress', + 'missingok', + 'rotate 30', + 'daily', + 'notifempty', + ], + require => Service['zuul-fingergw'], + } +}