0

I am running Linux on a TI-J7 embedded board. It is using syslogd from busybox. But the issue I am facing with syslog is it overwrites logfile when it exceeds 200kb size and so not able to collect more logs. (When it reaches 200k, log file is truncated and new logs by syslog are written to same file)

I am sure that it is not being rotated by logrotate because I have not configured logrotate and there is no configuration of size based rotation in the /etc/logrotate.conf

Following is the /etc/syslog.conf

#  /etc/syslog.conf     Configuration file for busybox's syslogd utility

Following is the /etc/syslog-startup.conf

# /etc/init.d/syslog[.busybox] to set syslog configuration at start time.

DESTINATION=file                # log destinations (buffer file remote)
#LOGFILE=/var/log/messages      # where to log (file)
LOGFILE=/opt/vision_apps/log.log        # where to log (file)
REMOTE=loghost:514              # where to log (syslog remote)
REDUCE=no                       # reduce-size logging
DROPDUPLICATES=no               # whether to drop duplicate log entries
#ROTATESIZE=0                   # rotate log if grown beyond X [kByte]
#ROTATEGENS=3                   # keep X generations of rotated logs
BUFFERSIZE=64                   # size of circular buffer [kByte]
FOREGROUND=no                   # run in foreground (don't use!)
#LOGLEVEL=5                     # local log level (between 1 and 8)

Following is /etc/init.d/syslog

#! /bin/sh
### BEGIN INIT INFO
# Provides:             sysklogd
# Required-Start:       $remote_fs $time
# Required-Stop:        $remote_fs $time
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    System logger
### END INIT INFO

set -e

if [ -f /etc/syslog-startup.conf ]; then
  . /etc/syslog-startup.conf
  LOG_LOCAL=0
  LOG_REMOTE=0
  for D in $DESTINATION; do
        if [ "$D" = "buffer" ]; then
                SYSLOG_ARGS="$SYSLOG_ARGS -C$BUFFERSIZE"
                LOG_LOCAL=1
        elif [ "$D" = "file" ]; then
                if [ -n "$LOGFILE" ]; then
                        SYSLOG_ARGS="$SYSLOG_ARGS -O $LOGFILE"
                fi
                if [ -n "$ROTATESIZE" ]; then
                        SYSLOG_ARGS="$SYSLOG_ARGS -s $ROTATESIZE"
                fi
                if [ -n "$ROTATEGENS" ]; then
                        SYSLOG_ARGS="$SYSLOG_ARGS -b $ROTATEGENS"
                fi
                LOG_LOCAL=1
        elif [ "$D" = "remote" ]; then
                SYSLOG_ARGS="$SYSLOG_ARGS -R $REMOTE"
                LOG_REMOTE=1
        fi
  done
  if [ "$LOG_LOCAL" = "1" -a "$LOG_REMOTE" = "1" ]; then
        SYSLOG_ARGS="$SYSLOG_ARGS -L"
  fi
  if [ "$REDUCE" = "yes" ]; then
        SYSLOG_ARGS="$SYSLOG_ARGS -S"
  fi
  if [ "$DROPDUPLICATES" = "yes" ]; then
      SYSLOG_ARGS="$SYSLOG_ARGS -D"
  fi
  if [ -n "$LOGLEVEL" ]; then
      SYSLOG_ARGS="$SYSLOG_ARGS -l $LOGLEVEL"
  fi
else
  # default: log to 16K shm circular buffer
  SYSLOG_ARGS="-C"
fi

waitpid ()
{
  pid=$1
  # Give pid a chance to exit before we restart with a 5s timeout in 1s intervals
  if [ -z "$pid" ]; then
    return
  fi
  timeout=5;
  while [ $timeout -gt 0 ]
  do
    timeout=$(( $timeout-1 ))
    kill -0 $pid 2> /dev/null || break
    sleep 1
  done
}

case "$1" in
  start)
  echo -n "Starting syslogd/klogd: "
  start-stop-daemon -S -b -n syslogd -a /sbin/syslogd -- -n $SYSLOG_ARGS
  start-stop-daemon -S -b -n klogd -a /sbin/klogd -- -n
  echo "done"
  ;;
  stop)
  echo -n "Stopping syslogd/klogd: "
  start-stop-daemon -K -n syslogd
  start-stop-daemon -K -n klogd
  echo "done"
  ;;
  restart)
  pid1=`pidof syslogd`
  pid2=`pidof klogd`
  $0 stop
  waitpid $pid1
  waitpid $pid2
  $0 start
  ;;
  *)
  echo "Usage: syslog { start | stop | restart }" >&2
  exit 1
  ;;
esac

exit 0
2
  • Hi, I would set the variables ROTATESIZE & the ROTATEGENS in config which will for the first set the max size of the logfile, the second will add a move from the log to log.1 and create another.
    – admstg
    Commented Aug 29, 2022 at 7:02
  • @admstg that seemed to work and now the log size if going beyond 200k, but after my set size, it is overwriting again and not creating new log file. As per this command, it should keep 4 old logs: /sbin/syslogd -n -O /opt/vision_apps/log.log -s 400 -b 4 Commented Aug 29, 2022 at 9:46

1 Answer 1

0

Since you are sourcing the /etc/syslog-startup.conf file within syslog startup file: /etc/init.d/syslog but within that you are passing two parameters ROTATESIZE and ROTATEGENS when those were not set as in:

if [ -n "$ROTATESIZE" ]; then
        SYSLOG_ARGS="$SYSLOG_ARGS -s $ROTATESIZE"
fi
if [ -n "$ROTATEGENS" ]; then
        SYSLOG_ARGS="$SYSLOG_ARGS -b $ROTATEGENS"

that means null value are passing into those parameters when the syslog starts.

what you need do is either set a fixed value when those are not set, such as below (rotate when 200K and 4 rotate files):

if [ -n "$ROTATESIZE" ]; then
        SYSLOG_ARGS="$SYSLOG_ARGS -s 200"
fi
if [ -n "$ROTATEGENS" ]; then
        SYSLOG_ARGS="$SYSLOG_ARGS -b 4"

... or change all [ -n $variable ] to [ ! -n $variable ] AND comment-out those parameters (ROTATESIZE, ROTATEGENS and others) in the /etc/syslog-startup.conf, which it will then read and set those value from the startup configuration file when it's non-empty value.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .