Added logrotation to syslog::standalone
This commit is contained in:
parent
d71553830d
commit
bbf1e6a22b
3 changed files with 83 additions and 0 deletions
1
CREDITS
1
CREDITS
|
@ -11,3 +11,4 @@ Additional people who have contributed patches:
|
|||
Juhani Eronen
|
||||
Lari Huttunen
|
||||
Marko Laakso
|
||||
Mikko Kenttälä
|
||||
|
|
64
syslog/files/logarchiver.sh
Executable file
64
syslog/files/logarchiver.sh
Executable file
|
@ -0,0 +1,64 @@
|
|||
#!/bin/sh
|
||||
ARCHIVEFILES="all.log"
|
||||
LOGDIR="/srv/log"
|
||||
DATE=`date +%Y-%m-%d`
|
||||
YEAR=`date +%Y`
|
||||
ARCHIVEDIR="/srv/log/archive/" #archivedlogs will be in this
|
||||
#directory + $YEAR
|
||||
umask 027
|
||||
|
||||
myerror(){
|
||||
echo "Error: $*" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
archive_log(){
|
||||
FILE="${1}"
|
||||
DEST="${2}"
|
||||
|
||||
if [ -f "${DEST}" -o -f "${DEST}.gz" ]; then
|
||||
echo "Skipping ${FILE}: Archive already exists" 1>&2
|
||||
else
|
||||
echo "Archiving file ${FILE} to ${DEST}"
|
||||
mv "${FILE}" "${DEST}"
|
||||
touch ${FILE}
|
||||
LOGS="${LOGS} ${DEST}"
|
||||
fi
|
||||
}
|
||||
|
||||
restart_syslog(){
|
||||
for i in syslog.pid rsyslogd.pid syslogd.pid ; do
|
||||
if [ -f "/var/run/$i" ]; then
|
||||
PIDFILE="/var/run/$i"
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "blah${PIDFILE}" = "blah" ]; then
|
||||
myerror "Cannot find syslog pid file" 1>&2
|
||||
fi
|
||||
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
|
||||
[ -f "${LOGDIR}/${logfile}" ] || myerror "File not found: ${logfile}"
|
||||
archive_log "${LOGDIR}/${logfile}" "${ARCHIVEDIR}/${logfile}.${DATE}"
|
||||
done
|
||||
restart_syslog
|
||||
for zipfile in ${ARCHIVEFILES} ; do
|
||||
gzip -f "${ARCHIVEDIR}/${zipfile}.${DATE}" || myerror "Error while gzipping ${ARCHIVEDIR}/${zipfile}"
|
||||
done
|
||||
}
|
||||
|
||||
case "x$1" in
|
||||
"x-v"|"x--verbose")
|
||||
archive
|
||||
;;
|
||||
*)
|
||||
archive >> /dev/null
|
||||
;;
|
||||
esac
|
|
@ -180,6 +180,24 @@ class syslog::standalone {
|
|||
target => "/srv/log/all.log",
|
||||
}
|
||||
|
||||
file { "/usr/local/sbin/logarchiver.sh":
|
||||
ensure => present,
|
||||
source => "puppet:///modules/syslog/logarchiver.sh",
|
||||
mode => 0755,
|
||||
owner => "root",
|
||||
group => $operatingsystem ? {
|
||||
"openbsd" => "wheel",
|
||||
default => "root",
|
||||
},
|
||||
}
|
||||
cron { "logarchiver.sh":
|
||||
command => "/usr/local/sbin/logarchiver.sh",
|
||||
user => "root",
|
||||
hour => 0,
|
||||
minute => 0,
|
||||
require => File["/usr/local/sbin/logarchiver.sh"],
|
||||
}
|
||||
|
||||
case $syslog_type {
|
||||
"syslogd": { include syslog::standalone::syslogd }
|
||||
"rsyslog": { include syslog::standalone::rsyslog }
|
||||
|
|
Loading…
Add table
Reference in a new issue