米尔 syslogd 启动脚本和配置文件理解

个人的一些理解,欢迎指正。

/etc/inittab里id:5:initdefault:,所以启动时执行/etc/rc5.d里的脚本?,其中S20syslog -> ../init.d/syslog,最终启动脚本为/etc/init.d/syslog,所以修改/etc/syslog-startup.conf即可修改syslog参数。参考注释

root@myd-y6ul14x14:~# cat /etc/inittab 
# /etc/inittab: init(8) configuration.
# $Id: inittab,v 1.91 2002/01/25 13:35:21 miquels Exp $

# The default runlevel.
id:5:initdefault:

# Boot-time system configuration/initialization script.
# This is run first except when booting in emergency (-b) mode.
si::sysinit:/etc/init.d/rcS

# What to do in single-user mode.
~~:S:wait:/sbin/sulogin

# /etc/init.d executes the S and K scripts upon change
# of runlevel.
#
# Runlevel 0 is halt.
# Runlevel 1 is single-user.
# Runlevels 2-5 are multi-user.
# Runlevel 6 is reboot.

l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
# Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin
mxc0:12345:respawn:/bin/start_getty 115200 ttymxc0
# /sbin/getty invocations for the runlevels.
#
# The "id" field MUST be the same as the last
# characters of the device (after "tty").
#
# Format:
#  <id>:<runlevels>:<action>:<process>
#

1:12345:respawn:/sbin/getty 38400 tty1

root@myd-y6ul14x14:~# ls -l /etc/rc5.d/
lrwxrwxrwx    1 1000     1000            20 Aug 15  2020 S01networking -> ../init.d/networking
lrwxrwxrwx    1 1000     1000            16 Aug 15  2020 S02dbus-1 -> ../init.d/dbus-1
lrwxrwxrwx    1 1000     1000            14 Aug 15  2020 S09sshd -> ../init.d/sshd
lrwxrwxrwx    1 1000     1000            17 Aug 15  2020 S12rpcbind -> ../init.d/rpcbind
lrwxrwxrwx    1 1000     1000            21 Aug 15  2020 S15mountnfs.sh -> ../init.d/mountnfs.sh
lrwxrwxrwx    1 1000     1000            14 Aug 15  2020 S20apmd -> ../init.d/apmd
lrwxrwxrwx    1 1000     1000            20 Aug 15  2020 S20hwclock.sh -> ../init.d/hwclock.sh
lrwxrwxrwx    1 1000     1000            16 Aug 15  2020 S20syslog -> ../init.d/syslog
lrwxrwxrwx    1 1000     1000            22 Aug 15  2020 S21avahi-daemon -> ../init.d/avahi-daemon
lrwxrwxrwx    1 1000     1000            15 Aug 15  2020 S22ofono -> ../init.d/ofono
lrwxrwxrwx    1 1000     1000            15 Aug 15  2020 S64neard -> ../init.d/neard
lrwxrwxrwx    1 1000     1000            18 Aug 15  2020 S99rc.local -> ../init.d/rc.local
lrwxrwxrwx    1 1000     1000            22 Aug 15  2020 S99rmnologin.sh -> ../init.d/rmnologin.sh
lrwxrwxrwx    1 1000     1000            23 Aug 15  2020 S99stop-bootlogd -> ../init.d/stop-bootlogd

root@myd-y6ul14x14:~# cat /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存在
	. /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            #若DESTINATION=file则
			if [ -n "$LOGFILE" ]; then
				SYSLOG_ARGS="$SYSLOG_ARGS -O $LOGFILE"    #若LOGFILE非空则SYSLOG_ARGS添加log输出文件为LOGFILE
			fi
			if [ -n "$ROTATESIZE" ]; then
				SYSLOG_ARGS="$SYSLOG_ARGS -s $ROTATESIZE"   #若ROTATESIZE非空则SYSLOG_ARGS添加循环log单个文件最大大小为ROTATESIZE
			fi
			if [ -n "$ROTATEGENS" ]; then
				SYSLOG_ARGS="$SYSLOG_ARGS -b $ROTATEGENS"   #若ROTATEGENS非空则SYSLOG_ARGS添加循环log最大文件数
			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 process name to check, -a program to start (default is<executable>)
	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


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值