#! /bin/sh #------------------------------------------------------------------------------ # /etc/rc.d/syslogd - start syslogd # # Copyright (c) 2001-2004 Frank Meyer # # Creation: 31.12.2001 fm # Last Update: $Id$ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #------------------------------------------------------------------------------ SYSLOGD_OPTIONS='' SYSLOGD_MARK_INTERVAL='' pgmname=syslogd logrotate_path=/etc/logrotate.d log_path=/var/log basefile=/etc/config.d/base syslog_file=/etc/syslog.conf logrotate_file=$logrotate_path/syslog . $basefile #------------------------------------------------------------------------------ # create syslogd configuration #------------------------------------------------------------------------------ create_conf () { { echo "#-----------------------------------------------------------------" echo "# /etc/syslog.conf" echo "# This file has been created automatically by /etc/init.d/syslogd" echo "# If you want to change settings, edit /etc/config.d/base" echo "# and restart syslogd and klogd by '/etc/init.d/syslogd restart'" echo "#-----------------------------------------------------------------" idx=1 while [ $idx -le $SYSLOGD_DEST_N ] do eval dest='$SYSLOGD_DEST_'$idx echo "$dest" idx=`expr $idx + 1` done } > $syslog_file } #------------------------------------------------------------------------------ # create logrotate file #------------------------------------------------------------------------------ create_logrotate () { logfiles="" if tty -s then echo "creating logrotate configuration file ..." fi if [ "$START_SYSLOGD" = "yes" ] then # build logname list in $logfiles idx=1 while [ $idx -le $SYSLOGD_DEST_N ] do eval dest='$SYSLOGD_DEST_'$idx logname=`echo "$dest"|sed 's/.* //g'` # check for @IP-address values if echo "$logname" | grep -qv '^@'; then # check for devices like /dev/console if echo "$logname" | grep -qv '^/dev/'; then if [ "$logfiles" != '' ]; then logfiles="$logfiles $logname" else logfiles="$logname" fi fi fi idx=`expr $idx + 1` done # create logrotate configuration file, only if $logfiles is not empty if [ "$logfiles" != '' ]; then { echo "#-------------------------------------------------------" echo "# syslog file generated by $pgmname" echo "#" echo "# Do not edit this file, edit $basefile" echo "# and run \"$0 restart\"." echo "# Creation date: `date`" echo "#-------------------------------------------------------" echo echo "$logfiles {" echo " rotate $SYSLOGD_LOG_COUNT" echo " $SYSLOGD_LOG_INTERVAL" echo " compress" echo " missingok" echo " notifempty" echo " postrotate" idx=1 while [ $idx -le $SYSLOGD_DEST_N ] do eval logrotate_cmd='$SYSLOGD_DEST_'$idx'_LOGROTATE' if [ "$logrotate_cmd" != "" ] then echo " $logrotate_cmd" echo " sleep 3" fi idx=`expr $idx + 1` done echo " endscript" echo " }" echo } > $logrotate_file else # rm old logrotate configuration file rm -f $logrotate_file fi else # rm old logrotate configuration file rm -f $logrotate_file fi } #------------------------------------------------------------------------------ # main #------------------------------------------------------------------------------ case $1 in start) if [ "$START_SYSLOGD" = "yes" ] then if tty -s then /usr/local/bin/colecho "starting syslogd ..." gn fi options='' create_conf create_logrotate if [ "$SYSLOGD_OPTIONS" != "" ] then options="$options $SYSLOGD_OPTIONS" fi if [ "$SYSLOGD_MARK_INTERVAL" != "" ] then options="$options -m $SYSLOGD_MARK_INTERVAL" fi /sbin/syslogd $options if tty -s then /usr/local/bin/colecho "starting klogd ..." gn fi /sbin/klogd -c 1 fi ;; stop) if [ -f /var/run/syslogd.pid ] then if tty -s then /usr/local/bin/colecho "shutting down syslogd ..." gn fi /bin/kill `cat /var/run/syslogd.pid` fi if [ -f /var/run/klogd.pid ] then if tty -s then /usr/local/bin/colecho "shutting down klogd ..." gn fi /bin/kill `cat /var/run/klogd.pid` fi ;; restart) sh $0 stop sleep 2 sh $0 start ;; esac