Allow giving custom config for rsyslog and defining logs to rotate
This commit is contained in:
parent
8bcdebc69e
commit
16d9b2b42e
2 changed files with 87 additions and 38 deletions
|
@ -1,18 +1,21 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
ARCHIVEFILES="all.log"
|
|
||||||
LOGDIR="/srv/log"
|
LOGDIR="/srv/log"
|
||||||
DATE=`date +%Y-%m-%d`
|
ARCHIVE="${LOGDIR}/archive"
|
||||||
YEAR=`date +%Y`
|
|
||||||
ARCHIVEDIR="/srv/log/archive/" #archivedlogs will be in this
|
DATE="`date +%Y-%m-%d`"
|
||||||
#directory + $YEAR
|
YEAR="`date +%Y`"
|
||||||
|
|
||||||
umask 027
|
umask 027
|
||||||
|
|
||||||
myerror(){
|
myerror()
|
||||||
|
{
|
||||||
echo "Error: $*" 1>&2
|
echo "Error: $*" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
archive_log(){
|
archive_log()
|
||||||
|
{
|
||||||
FILE="${1}"
|
FILE="${1}"
|
||||||
DEST="${2}"
|
DEST="${2}"
|
||||||
|
|
||||||
|
@ -21,12 +24,13 @@ archive_log(){
|
||||||
else
|
else
|
||||||
echo "Archiving file ${FILE} to ${DEST}"
|
echo "Archiving file ${FILE} to ${DEST}"
|
||||||
mv "${FILE}" "${DEST}"
|
mv "${FILE}" "${DEST}"
|
||||||
touch ${FILE}
|
touch "${FILE}"
|
||||||
LOGS="${LOGS} ${DEST}"
|
LOGS="${LOGS} ${DEST}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
restart_syslog(){
|
restart_syslog()
|
||||||
|
{
|
||||||
for i in syslog.pid rsyslogd.pid syslogd.pid ; do
|
for i in syslog.pid rsyslogd.pid syslogd.pid ; do
|
||||||
if [ -f "/var/run/$i" ]; then
|
if [ -f "/var/run/$i" ]; then
|
||||||
PIDFILE="/var/run/$i"
|
PIDFILE="/var/run/$i"
|
||||||
|
@ -34,31 +38,40 @@ restart_syslog(){
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ "blah${PIDFILE}" = "blah" ]; then
|
if [ "blah${PIDFILE}" = "blah" ]; then
|
||||||
myerror "Cannot find syslog pid file" 1>&2
|
myerror "Cannot find syslog pid file"
|
||||||
fi
|
fi
|
||||||
kill -HUP `cat ${PIDFILE}`
|
kill -HUP `cat ${PIDFILE}`
|
||||||
}
|
}
|
||||||
archive(){
|
|
||||||
[ -d ${LOGDIR} ] || myerror "No such direcroty: ${LOGDIR}"
|
|
||||||
[ -d "${ARCHIVEDIR}" ] || myerror "No such archive directory: ${ARCHIVEDIR}"
|
|
||||||
[ -d "${ARCHIVEDIR}/${YEAR}" ] || mkdir ${ARCHIVEDIR}/${YEAR}
|
|
||||||
ARCHIVEDIR="${ARCHIVEDIR}/${YEAR}"
|
|
||||||
|
|
||||||
for logfile in ${ARCHIVEFILES} ; do
|
[ $# -gt 0 ] || myerror "Usage: `basename $0` <file|dir> [file|dir] ..."
|
||||||
[ -f "${LOGDIR}/${logfile}" ] || myerror "File not found: ${logfile}"
|
|
||||||
archive_log "${LOGDIR}/${logfile}" "${ARCHIVEDIR}/${logfile}.${DATE}"
|
[ -d ${LOGDIR} ] || myerror "Not a directory: ${LOGDIR}"
|
||||||
|
|
||||||
|
while [ "$*" ]; do
|
||||||
|
if [ -f "${LOGDIR}/${1}" ]; then
|
||||||
|
dstdir=${ARCHIVE}/${YEAR}
|
||||||
|
dstfile=${dstdir}/`basename ${1}`.${DATE}
|
||||||
|
[ -d "${dstdir}" ] || mkdir -p ${dstdir}
|
||||||
|
archive_log ${LOGDIR}/${1} ${dstfile}
|
||||||
|
elif [ -d "${LOGDIR}/${1}" ]; then
|
||||||
|
for f in ${LOGDIR}/${1}/*.log; do
|
||||||
|
if [ -f "${f}" ]; then
|
||||||
|
dstdir=${ARCHIVE}/${1}/${YEAR}
|
||||||
|
dstfile=${dstdir}/`basename ${f}`.${DATE}
|
||||||
|
[ -d "${dstdir}" ] || mkdir -p ${dstdir}
|
||||||
|
archive_log ${f} ${dstfile}
|
||||||
|
else
|
||||||
|
echo "Skipping ${f}: not a file" 1>&2
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
else
|
||||||
|
echo "Skipping ${1}: not a file or directory" 1>&2
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
restart_syslog
|
restart_syslog
|
||||||
for zipfile in ${ARCHIVEFILES} ; do
|
|
||||||
gzip -f "${ARCHIVEDIR}/${zipfile}.${DATE}" || myerror "Error while gzipping ${ARCHIVEDIR}/${zipfile}"
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
case "x$1" in
|
for log in ${LOGS}; do
|
||||||
"x-v"|"x--verbose")
|
gzip -f ${log} || myerror "Error while gzipping ${log}"
|
||||||
archive
|
done
|
||||||
;;
|
|
||||||
*)
|
|
||||||
archive >> /dev/null
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
|
|
|
@ -212,8 +212,15 @@ class syslog::client::rsyslog {
|
||||||
# $syslog_datadir:
|
# $syslog_datadir:
|
||||||
# Directory where to store logs. Defaults to /srv/log.
|
# Directory where to store logs. Defaults to /srv/log.
|
||||||
#
|
#
|
||||||
|
# $syslog_rotate:
|
||||||
|
# Array of log files to rotate. Defaults to 'all.log'.
|
||||||
|
#
|
||||||
class syslog::common::standalone inherits syslog::common {
|
class syslog::common::standalone inherits syslog::common {
|
||||||
|
|
||||||
|
if !$syslog_rotate {
|
||||||
|
$syslog_rotate = [ "all.log" ]
|
||||||
|
}
|
||||||
|
|
||||||
if $syslog_datadir {
|
if $syslog_datadir {
|
||||||
file { $syslog_datadir:
|
file { $syslog_datadir:
|
||||||
ensure => directory,
|
ensure => directory,
|
||||||
|
@ -277,8 +284,9 @@ class syslog::common::standalone inherits syslog::common {
|
||||||
default => "root",
|
default => "root",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
$syslog_rotate_files = inline_template('<%= syslog_rotate.join(" ") -%>')
|
||||||
cron { "logarchiver.sh":
|
cron { "logarchiver.sh":
|
||||||
command => "/usr/local/sbin/logarchiver.sh",
|
command => "/usr/local/sbin/logarchiver.sh ${syslog_rotate_files} >/dev/null",
|
||||||
user => "root",
|
user => "root",
|
||||||
hour => 0,
|
hour => 0,
|
||||||
minute => 0,
|
minute => 0,
|
||||||
|
@ -370,3 +378,31 @@ class syslog::server::rsyslog inherits syslog::client::rsyslog {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Install syslog server with custom configuration.
|
||||||
|
#
|
||||||
|
class syslog::custom inherits syslog::common::standalone {
|
||||||
|
|
||||||
|
case $syslog_type {
|
||||||
|
"syslogd": { fail("Server for \$syslog_type '$syslog_type' not yet supported.") }
|
||||||
|
"rsyslog": { include syslog::custom::rsyslog }
|
||||||
|
default: { fail("Unknown \$syslog_type '$syslog_type'") }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Install syslog server using rsyslog with custom configuration.
|
||||||
|
#
|
||||||
|
class syslog::custom::rsyslog inherits syslog::client::rsyslog {
|
||||||
|
|
||||||
|
File["/etc/rsyslog.conf"] {
|
||||||
|
content => undef,
|
||||||
|
source => [ "puppet:///files/syslog/rsyslog.conf.${homename}",
|
||||||
|
"puppet:///files/syslog/rsyslog.conf", ],
|
||||||
|
require => [ File["/srv/log"],
|
||||||
|
File["/var/log/all.log"], ],
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue