aboutsummaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/busybox/files/syslog
blob: 49033c1755a532ba794573a79cb55eda70609bc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#! /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 syslogd`
	$0 stop
	waitpid $pid1
	waitpid $pid2
	$0 start
	;;
  *)
	echo "Usage: syslog { start | stop | restart }" >&2
	exit 1
	;;
esac

exit 0