Subversion Repositories configs

Rev

Rev 34 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 - 1
#!/bin/bash
2
#
3
# netconsole 	This loads the netconsole module with the configured parameters.
4
#
5
# chkconfig: - 50 50
6
# description: Initializes network console logging
7
# config: /etc/sysconfig/netconsole
8
#
9
# Copyright 2002 Red Hat, Inc.
10
#
11
# Based in part on a shell script by
12
# Andreas Dilger <adilger@turbolinux.com>  Sep 26, 2001
13
 
14
PATH=/sbin:/usr/sbin:$PATH
15
RETVAL=0
16
SERVER_ADDRESS_RESOLUTION=
17
 
18
# Check that networking is up.
19
. /etc/sysconfig/network
20
 
21
# Source function library.
22
. /etc/rc.d/init.d/functions
23
 
24
# Default values
25
LOCALPORT=6666
26
DEV=
27
 
28
SYSLOGADDR=
29
SYSLOGPORT=514
30
SYSLOGMACADDR=
31
 
32
kernel=$(uname -r | cut -d. -f1-2)
33
 
34
usage ()
35
{
36
	echo $"Usage: $0 {start|stop|status|restart|condrestart}" 1>&2
37
	RETVAL=2
38
}
39
 
40
print_address_info ()
41
{
42
	local host=$1
43
	local route via target
44
 
45
	route=$(LANG=C ip -o route get to $host/32)
46
 
47
	[ -z "$DEV" ] && DEV=$(echo $route | sed "s|.* dev \([^ ]*\).*|\1|")
48
	echo "DEV=$DEV"
49
	echo "LOCALADDR=$(echo $route | sed "s|.* src \([^ ]*\).*|\1|")"
50
	if [[ $route == *" via "* ]] ; then
51
		via=$(echo $route | sed "s|.* via \([^ ]*\).*|\1|")
52
		target=$via
53
	else
54
		target=$host
55
	fi
56
	if [ -z "$SYSLOGMACADDR" ]; then
57
		arp=$(LANG=C /sbin/arping -f -c 1 -I $DEV $target 2>/dev/null | awk '/ reply from .*[.*]/ { print gensub(".* reply from .* \\[(.*)\\].*","\\1","G"); exit }')
58
		[ -n "$arp" ] && echo "SYSLOGMACADDR=$arp"
59
	fi
60
}
61
 
62
start ()
63
{
64
	[ -f /etc/sysconfig/netconsole ] || exit 6
65
	. /etc/sysconfig/netconsole
66
 
67
	SYSLOGOPTS=
68
	# syslogd server, if any
69
	if [ -n "$SYSLOGADDR" ]; then
70
		MATCH="^([0-9]{1,3}\.){3}[0-9]{1,3}$"
71
		if ! [[ "$SYSLOGADDR" =~ $MATCH ]]; then
72
			SYSLOGADDR=$(LANG=C host $SYSLOGADDR 2>/dev/null | awk '/has address / { print $NF }')
73
		fi
74
	fi
75
	if [ -z "$SYSLOGADDR" ] ; then
76
		echo $"Server address not specified in /etc/sysconfig/netconsole" 1>&2
77
		exit 6
78
	fi
79
	eval $(print_address_info $SYSLOGADDR)
80
 
81
	if [ -z "$SYSLOGMACADDR" ]; then
82
		echo $"netconsole: can't resolve MAC address of $SYSLOGADDR" 1>&2
83
		exit 1
84
	fi
85
 
86
	SYSLOGOPTS="netconsole=$LOCALPORT@$LOCALADDR/$DEV,$SYSLOGPORT@$SYSLOGADDR/$SYSLOGMACADDR "
87
 
88
	/usr/bin/logger -p daemon.info -t netconsole: inserting netconsole module with arguments \
89
	$SYSLOGOPTS
90
	if [ -n "$SYSLOGOPTS" ]; then
91
		action $"Initializing netconsole" modprobe netconsole \
92
			$SYSLOGOPTS
93
		[ "$?" != "0" ] && RETVAL=1
94
	fi
95
	touch /var/lock/subsys/netconsole
96
}
97
 
98
stop ()
99
{
100
	if /sbin/lsmod | grep netconsole >/dev/null 2>&1 ; then
101
	    action $"Disabling netconsole" rmmod netconsole;
102
	    [ "$?" != "0" ] && RETVAL=1
103
	fi
104
 
105
	rm -f /var/lock/subsys/netconsole
106
}
107
 
108
status ()
109
{
110
	if /sbin/lsmod | grep netconsole >/dev/null 2>&1 ; then
111
		echo $"netconsole module loaded"
112
		RETVAL=0
113
	else
114
		echo $"netconsole module not loaded"
115
		RETVAL=3
116
	fi
117
}
118
 
119
 
120
restart ()
121
{
122
	stop
123
	start
124
}
125
 
126
condrestart ()
127
{
128
	[ -e /var/lock/subsys/netconsole ] && restart
129
}
130
 
131
 
132
case "$1" in
133
    stop) stop ;;
134
    status) status ;;
135
    start|restart|reload|force-reload) restart ;;
136
    condrestart) condrestart ;;
137
    *) usage ;;
138
esac
139
 
140
exit $RETVAL