From 3f4f1d9820c0ba7092acf619fc5deb12c1e5aaee Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 12 Jul 2017 05:05:38 -0500 Subject: [PATCH] Add support for zuul-web and scheduler connections Zuul v3 has a zuul-web service that provides web streaming and eventually other web content. Add support for running it. Also add it to the Apache mod_rewrite proxy info. While we're adding things, add proxy info for plugin connections, which should allow receiving github webhook events. Change-Id: Ic79681b287dbd1a44469da70c680060940734f40 --- files/web-logging.conf | 49 +++++++++++++++ files/zuul-web.init | 127 ++++++++++++++++++++++++++++++++++++++ manifests/init.pp | 5 ++ manifests/web.pp | 72 +++++++++++++++++++++ templates/zuul.vhost.erb | 4 ++ templates/zuulv3.conf.erb | 9 +++ 6 files changed, 266 insertions(+) create mode 100644 files/web-logging.conf create mode 100644 files/zuul-web.init create mode 100644 manifests/web.pp diff --git a/files/web-logging.conf b/files/web-logging.conf new file mode 100644 index 0000000..b3ff4d3 --- /dev/null +++ b/files/web-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/web-debug.log',) + +[handler_normal] +level=INFO +class=logging.handlers.WatchedFileHandler +formatter=simple +args=('/var/log/zuul/web.log',) + +[formatter_simple] +format=%(asctime)s %(levelname)s %(name)s: %(message)s +datefmt= diff --git a/files/zuul-web.init b/files/zuul-web.init new file mode 100644 index 0000000..821745a --- /dev/null +++ b/files/zuul-web.init @@ -0,0 +1,127 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: zuul-web +# 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 Web" +NAME=zuul-web +DAEMON=/usr/local/bin/zuul-web +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() +{ + $DAEMON stop + return 0 +} + +# +# Function that sends a SIGHUP to the daemon/service +# +do_reload() { + $DAEMON reconfigure + 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-web 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/init.pp b/manifests/init.pp index 92f6adc..99a63b1 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -78,6 +78,8 @@ class zuul ( $gearman_server_ssl_cert = undef, $gearman_server_ssl_key = undef, $gearman_ssl_ca = undef, + $zuul_web_url = 'http://127.0.0.1:9000', + $zuul_scheduler_url = 'http://127.0.0.1:8001', ) { include ::httpd include ::pip @@ -564,6 +566,9 @@ class zuul ( if ! defined(Httpd::Mod['cgid']) { httpd::mod { 'cgid': ensure => present } } + if !defined(Mod['proxy_wstunnel']) { + httpd::mod { 'proxy_wstunnel': ensure => present } + } case $::lsbdistcodename { 'precise': { diff --git a/manifests/web.pp b/manifests/web.pp new file mode 100644 index 0000000..c55f032 --- /dev/null +++ b/manifests/web.pp @@ -0,0 +1,72 @@ +# 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::web +# +class zuul::web ( + $ensure = undef, + $manage_log_conf = true, + $web_listen_address = '127.0.0.1', + $web_listen_port = 9000, +) { + + service { 'zuul-web': + ensure => $ensure, + name => 'zuul-web', + enable => true, + hasrestart => true, + require => [File['/etc/init.d/zuul-web'], + Class['zuul::systemd_reload']] + } + + file { '/etc/init.d/zuul-web': + ensure => present, + owner => 'root', + group => 'root', + mode => '0555', + source => 'puppet:///modules/zuul/zuul-web.init', + notify => Class['zuul::systemd_reload'], + } + + if $manage_log_conf { + file { '/etc/zuul/web-logging.conf': + ensure => present, + source => 'puppet:///modules/zuul/web-logging.conf', + } + } + + include ::logrotate + ::logrotate::file { 'web.log': + log => '/var/log/zuul/web.log', + options => [ + 'compress', + 'missingok', + 'rotate 30', + 'daily', + 'notifempty', + ], + require => Service['zuul-web'], + } + ::logrotate::file { 'web-debug.log': + log => '/var/log/zuul/web-debug.log', + options => [ + 'compress', + 'missingok', + 'rotate 30', + 'daily', + 'notifempty', + ], + require => Service['zuul-web'], + } +} diff --git a/templates/zuul.vhost.erb b/templates/zuul.vhost.erb index 1d01836..acacb42 100644 --- a/templates/zuul.vhost.erb +++ b/templates/zuul.vhost.erb @@ -100,6 +100,10 @@ <% end -%> RewriteRule ^/status.json$ <%= @zuul_status_url %>/status.json [P] RewriteRule ^/status/(.*) <%= @zuul_status_url %>/status/$1 [P] + RewriteRule ^/connection/(.*) <%= @zuul_scheduler_url %>/connection/$1 [P] + RewriteRule ^/console-stream <%= @zuul_web_url %>/console-stream [P] + RewriteRule ^/static/(.*) <%= @zuul_web_url %>/static/$1 [P] + RewriteRule ^/jobs/(.*) <%= @zuul_web_url %>/jobs/$1 [P] AddOutputFilterByType DEFLATE application/json diff --git a/templates/zuulv3.conf.erb b/templates/zuulv3.conf.erb index 6939b74..0fc861e 100644 --- a/templates/zuulv3.conf.erb +++ b/templates/zuulv3.conf.erb @@ -56,6 +56,15 @@ trusted_rw_dirs=<%= @trusted_rw_dirs.join(':') %> untrusted_ro_dirs=<%= @untrusted_ro_dirs.join(':') %> untrusted_rw_dirs=<%= @untrusted_rw_dirs.join(':') %> +[web] +log_config=/etc/zuul/web-logging.conf +<% if @web_listen_address != "" -%> +listen_address=<%= @web_listen_address %> +<% end -%> +<% if @web_listen_port != "" -%> +listen_port=<%= @web_listen_port %> +<% end -%> + <% @connections.each do |connection| -%> [connection "<%= connection['name'] %>"] <% connection.each do |key,value| -%>