System Logging

1 Enable syslog logging

Simply start the syslog daemon and/or the kernel log daemon.
Commands:

~ # syslogd
~ # klogd
~ # ps -ef | grep -e sysl -e klog
  848 root        376 S   syslogd
  851 root        356 S   klogd

Output is stored in /var/log/messages

2 Automatic syslog/klog startup

Note Script development not complete. Basically working, but feature to keep last X syslogs not yet included

Create a new script called: /etc/init.d/S10startSyslog

Content:

#!/bin/sh
#
# This script starts/stops the syslogd and klogs
#

SYSLOGD_BIN=/sbin/syslogd
KLOGD_BIN=/sbin/klogd
#KEEP_LAST=3

start() {
        echo "Starting syslog/klog daemons ..."

        # Background info:
        # Because on R700 the /var directory is a link to /tmp, and /tmp is only a
        # ramdisk filled with /tmp_orig content during boot, per default the content of /tmp and this way
        # /var/log is always empty after each boot.
        # To keep the logfile, log is on syslog start linked to a location on /tmp_orig

        # move old syslog to .old / syslog.timestamp
        if [ -f /var/log/messages ]
        then
          CDATE=$(date +%Y%M%d%H%M%S)
          cp /var/log/messages /tmp_orig/log/messages.$CDATE
          mv /var/log/messages /var/log/messages.$CDATE
        fi

    # cleanup
    # delete old syslogs except the last $KEEP_LAST logs
    # while $(ll /tmp_orig/log/messages.* | wc -l > $KEEP_LAST do; delete oldest; loop

        # create new syslog; default/used location /var/log/messages; link to permanent storage
        if [ ! -f /var/log/messages ]
        then
          echo "  Creating/linking /var/log/messages"
          /bin/touch /tmp_orig/log/messages
          /bin/ln -s /tmp_orig/log/messages /var/log/messages
        fi
        # give info if new syslog cannot be created
        if [ ! -f /var/log/messages ]
        then
          echo "  Warning: /var/log/messages could not be created"
        fi
        # somehow the syslog and klog must not run in foreground,
        # otherwise they'll stop once the initialisation is completed
        /sbin/syslogd
        /sbin/klogd
        echo "Starting syslog/klog daemons completed."
}
stop() {
        echo "Stopping syslog/klogd daemons via kill..."

        # Take care of syslogd
        # Find the PID of the daemons
        SYSLOGD_PID=$(ps | grep $SYSLOGD_BIN | grep -v 'grep' | tail -n 1 | awk '{ print $1 }')
        # kill if a process was found
        if [ "$SYSLOGD_PID" -ne "" ]
        then
          echo "  PID of $SYSLOGD_BIN is $SYSLOGD_PID ... killing ..."
          kill $SYSLOGD_PID
        else
          echo "  $SYSLOGD_BIN was not running."
        fi

        # take care of klog, find its process number
        KLOGD_PID=$(ps | grep $KLOGD_BIN | grep -v 'grep' | tail -n 1 | awk '{ print $1 }')
        if [ "$KLOGD_PID" -ne "" ]
        then
          echo "  PID of $KLOGD_BIN is $KLOGD_PID ... killing ..."
          kill $KLOGD_PID
        else
          echo "  $KLOGD_BIN was not running."
        fi
        echo "Stopping syslog/klogd daemons completed."
}
restart() {
        stop
        start
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|reload)
        restart
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac

exit $?

Now syslog services will be started on boot / stopped on shutdown

page_revision: 0, last_edited: 1217516243|%e %b %Y, %H:%M %Z (%O ago)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License