aboutsummaryrefslogtreecommitdiffstats
path: root/main/sysklogd/sysklogd.daily
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2009-08-05 08:17:53 +0000
committerNatanael Copa <ncopa@alpinelinux.org>2009-08-05 08:17:53 +0000
commit74294c061a5ecfa0986ac7684de197987d435bea (patch)
treed8a849084197503a7d9dd52eb3be2d7c670f2f20 /main/sysklogd/sysklogd.daily
parent11760a8485da27422f78ee8212d5413ec93ff0f3 (diff)
downloadaports-74294c061a5ecfa0986ac7684de197987d435bea.tar.bz2
aports-74294c061a5ecfa0986ac7684de197987d435bea.tar.xz
main/sysklogd: use cron to rotate logs rather than logrotate
The cronscript parses the syslog.conf and dynamically rotates all configured log files, while logrotate is a static list. This way we avoid needing to update the logrotate script each time you change syslog.conf
Diffstat (limited to 'main/sysklogd/sysklogd.daily')
-rwxr-xr-xmain/sysklogd/sysklogd.daily82
1 files changed, 82 insertions, 0 deletions
diff --git a/main/sysklogd/sysklogd.daily b/main/sysklogd/sysklogd.daily
new file mode 100755
index 0000000000..79e85fb468
--- /dev/null
+++ b/main/sysklogd/sysklogd.daily
@@ -0,0 +1,82 @@
+#!/bin/sh
+# This is a shell script replacement for the sysklogd's logrotate cron script
+# and syslogd-listfiles perl script.
+# Copyright (C) 2008 N. Angelacos for the Alpine Linux project - GPL2
+
+
+CONF="/etc/syslog.conf"
+
+
+syslogd_listfiles() {
+ # List the target files from syslog.conf
+
+ local skip="auth"
+ [ "$1" = "--auth" ] && skip=" "
+
+ # the while loop joins lines that end in "\"
+ # the sed (in order)-
+ # strips comments;
+ # collapses spaces/tabs to 1 space;
+ # deletes the "-" in front of the filename;
+ # deletes lines that have the "skip" facility
+ # deletes the facility (leaving just the filename)
+ # deletes lines that are not filenames with leading "/"
+ while read a ; do echo "$a"; done < $CONF |\
+ sed -n "/^ *#/D; /^[ ]*$/D; s/[ ]\+/ /g; \
+ s+ -/+ /+g; /^.*\($skip\)[^ ]* /D; \
+ s/^[^ ]* //; /^[^\\/]/D; P" |\
+ sort | uniq
+}
+
+# dumb little savelog - no error checking here
+savelog () {
+ local group="adm"
+ local mode="644"
+ local user="root"
+ local cycle=2
+ local logfile=""
+
+ # parse args
+ while getopts "g:u:m:c:" opt; do
+ case $opt in
+ g) group=$OPTARG ;;
+ u) user=$OPTARG ;;
+ m) mode=$OPTARG ;;
+ c) cycle=$OPTARG ;;
+ *) echo "unknown option: $opt" >&2 && return 1;;
+ esac
+ done
+ shift $(( $OPTIND - 1 ))
+ logfile=$1
+
+ # Cycle the logs
+ while [ $cycle -ne 0 ]; do
+ p=$cycle
+ cycle=$(( $cycle - 1 ))
+ a=$logfile.$cycle*
+ b=$( echo $a | sed "s/\.$cycle/\.$p/")
+ [ -f $a ] && mv $a $b
+ done
+
+ # compress .1 and let .0 be uncompressed
+ [ -f $logfile.1 ] && gzip $logfile.1
+ [ -f $logfile ] && mv $logfile $logfile.0
+
+ # set permissions
+ chown $user:$group $logfile.* 2>/dev/null
+ chmod $mode $logfile.* 2>/dev/null
+}
+
+
+# Main script
+
+for LOG in $( syslogd_listfiles ); do
+ [ -f $LOG ] && savelog -g adm -m 640 -u root -c 7 $LOG
+done
+
+for LOG in $(syslogd_listfiles --auth); do
+ [ -f $LOG ] && savelog -g adm -m 640 -u root -c 7 $LOG
+done
+
+killall -HUP syslogd
+