From: Tim Johnson Date: Mon, 9 Sep 2019 17:51:54 +0000 (-0700) Subject: Capture sudo log on builders X-Git-Tag: v0.44.1~6 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F65%2F61665%2F7;p=releng%2Fglobal-jjb.git Capture sudo log on builders Created new script sudo-logs.sh to archive the sudo logs Issue: RELENG-1994 Change-Id: I86a44e6abf18e35c7dc0e1840797e0dde5c764fb Signed-off-by: Tim Johnson --- diff --git a/jjb/lf-macros.yaml b/jjb/lf-macros.yaml index 6a2ea526..c06f0ce2 100644 --- a/jjb/lf-macros.yaml +++ b/jjb/lf-macros.yaml @@ -76,6 +76,8 @@ # Ensure python-tools are installed in case job template does not # call the lf-infra-pre-build macro. - ../shell/python-tools-install.sh + - shell: !include-raw: + - ../shell/sudo-logs.sh - shell: !include-raw: - ../shell/logs-deploy.sh - shell: !include-raw: diff --git a/releasenotes/notes/archive-sudo-logs-a9af4aff811feec5.yaml b/releasenotes/notes/archive-sudo-logs-a9af4aff811feec5.yaml new file mode 100644 index 00000000..d0be097b --- /dev/null +++ b/releasenotes/notes/archive-sudo-logs-a9af4aff811feec5.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + + Archive 'sudo' logs. The log will be located in the 'sudo' sub-directory of + the archive. The actual name of the log-file depends on the OS of the + builder. diff --git a/shell/sudo-logs.sh b/shell/sudo-logs.sh new file mode 100755 index 00000000..d925434f --- /dev/null +++ b/shell/sudo-logs.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# SPDX-License-Identifier: EPL-1.0 +############################################################################## +# Copyright (c) 2019 The Linux Foundation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +############################################################################## +echo "---> sudo-logs.sh" + +set -eu -o pipefail -o noglob + +# Copy/Generate 'sudo' log and copy to archive directory +function copy_log() +{ + case $os in + fedora|centos|redhat|ubuntu|debian) + if ! sudo cp $sudo_log /tmp; then + echo "Unable to archive 'sudo' logs ($sudo_log)" + return + fi + ;; + suse) + # Do I need 'sudo' to run 'journalctl'? + journalctl | grep sudo > $sudo_log + ;; + *) echo "Unexpected 'operatingsystem': $os" + exit 1 + ;; + esac + sudo_log=$(basename $sudo_log) + sudo chown jenkins:jenkins /tmp/$sudo_log + chmod 0644 /tmp/$sudo_log + mkdir -p $WORKSPACE/archives/sudo + mv /tmp/$sudo_log $WORKSPACE/archives/sudo/$sudo_log + +} # End copy_log() + +echo "Archiving 'sudo' log.." +os=$(facter operatingsystem | tr '[:upper:]' '[:lower:]') +case $os in + fedora|centos|redhat) sudo_log=/var/log/secure ;; + ubuntu|debian) sudo_log=/var/log/auth.log ;; + suse) sudo_log=/tmp/sudo.log ;; + *) echo "Unexpected 'operatingsystem': $os" + exit 1 + ;; +esac + +copy_log