如何让 syslogd/klogd 在重新启动后附加到 syslog 而不是覆盖?

如何让 syslogd/klogd 在重新启动后附加到 syslog 而不是覆盖?

重新启动或崩溃后,系统日志不会保存上一个会话的任何消息。我应该怎么做才能告诉 syslogd/klogd 附加到 syslog 而不是覆盖每个会话?我觉得我错过了一些明显的东西。

我的系统的一些背景:

  • 分配:Yocto(狭小)与 busybox
  • 启动klogd/syslogd的方法:在里面
  • 启动 configs/scrips klogd/syslogd 使用:/etc/syslog-startup.conf 和 /etc/init.d/syslog

/etc/syslog-startup.conf

# This configuration file is used by the busybox syslog init script,
# /etc/init.d/syslog[.busybox] to set syslog configuration at start time.

DESTINATION=file        # log destinations (buffer file remote)
LOGFILE=/var/log/syslog     # 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=100          # 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=8          # local log level (between 1 and 8)

/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

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)
    $0 stop
    $0 start
    ;;
  *)
    echo "Usage: syslog { start | stop | restart }" >&2
    exit 1
    ;;
esac

exit 0

答案1

似乎 /var/log/ 目录在启动时被重定向到 /var/volatile/log/ ,该目录作为 tempfs 安装,因此在重新启动/崩溃时不会保存数据。注释掉 /etc/fstab 文件中将 /var/volatile/ 目录挂载为 tmpfs 的行似乎有效。

相关内容