S03logrotate

Synopsys


#
# Need to fixup the logrotation
# we have created a new /var/log/slapd.log
#                       /var/log/device.log
#			/var/log/dhcpd.log
#
# The loghost machine should keep logs for 4 weeks as per the standard conf
# Non-loghost machines should only keep 7 days of logs.
# 
#

Script


echo "%Post: logrotation fixups"

SRV=`host -t SRV _tsltd._loghost._tcp.$DOMAINNAME`

if [ "$OS" == "fc4" ]; then
    LOGHOST=`echo SRV | cut -d" " -f8 | cut -d"." -f1`
else
    LOGHOST=`echo SRV | cut -d" " -f6 | cut -d"." -f1`
fi

if [ "$NODENAME" != "$LOGHOST" ]; then
    mv /etc/logrotate.conf /etc/logrotate.conf-$VERSION
    sed -e 's/weekly$/daily/' \
        -e 's/4 weeks/7 days/' \
        -e 's/^\(rotate\) 4/\1 7/' \
        /etc/logrotate.conf-$VERSION > /etc/logrotate.conf
fi

echo "%Post: logrotation slapd"
cat > /etc/logrotate.d/slapd <<EOF
/var/log/slapd.log {
    postrotate
# would be nice to kill -hup but doesn't appear to work 
# so this fixes it

        /sbin/service ldap restart 2> /dev/null || true
    endscript
}

EOF
echo "%Post: logrotation device.log"
cat > /etc/logrotate.d/device <<EOF
/var/log/device.log {
    postrotate
    /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

EOF
echo "%Post: logrotation dhcp.log"
cat > /etc/logrotate.d/dhcpd <<EOF
/var/log/dhcpd.log {
    postrotate
    /bin/kill -HUP `cat /var/run/dhcpd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

EOF

Examples and Testing





Marked up in XHTML - ©2005 Thoughtful Solutions Ltd.