aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--initscripts.spec2
-rw-r--r--rc.d/init.d/netconsole147
-rw-r--r--sysconfig/netconsole20
3 files changed, 169 insertions, 0 deletions
diff --git a/initscripts.spec b/initscripts.spec
index 644fdc09..c1513560 100644
--- a/initscripts.spec
+++ b/initscripts.spec
@@ -67,6 +67,7 @@ chmod 600 /var/log/btmp
/sbin/chkconfig --add netfs
/sbin/chkconfig --add network
+/sbin/chkconfig --add netconsole
# Handle converting prefdm back to respawn
if fgrep -q "x:5:once:/etc/X11/prefdm -nodaemon" /etc/inittab ; then
@@ -77,6 +78,7 @@ fi
if [ $1 = 0 ]; then
/sbin/chkconfig --del netfs
/sbin/chkconfig --del network
+ /sbin/chkconfig --del netconsole
fi
%triggerun -- initscripts < 7.62
diff --git a/rc.d/init.d/netconsole b/rc.d/init.d/netconsole
new file mode 100644
index 00000000..ba99e2cb
--- /dev/null
+++ b/rc.d/init.d/netconsole
@@ -0,0 +1,147 @@
+#!/bin/bash
+#
+# netconsole This loads the netconsole module with the configured parameters.
+#
+# chkconfig: - 50 50
+# description: Initializes network console logging
+# config: /etc/sysconfig/netconsole
+#
+# Copyright 2002 Red Hat, Inc.
+#
+# Based in part on a shell script by
+# Andreas Dilger <adilger@turbolinux.com> Sep 26, 2001
+
+PATH=/sbin:/usr/sbin:$PATH
+RETVAL=0
+SERVER_ADDRESS_RESOLUTION=
+
+# Check that networking is up.
+. /etc/sysconfig/network
+if [ ${NETWORKING} = "no" ]
+then
+ exit 0
+fi
+
+# Source function library.
+. /etc/rc.d/init.d/functions
+
+# Default values
+LOCALPORT=6666
+DEV=
+
+SYSLOGADDR=
+SYSLOGPORT=514
+SYSLOGMACADDR=
+
+kernel=`uname -r | cut -d. -f1-2`
+
+[ -f /etc/sysconfig/netconsole ] || exit 0
+. /etc/sysconfig/netconsole
+
+[ -z "$SYSLOGADDR" ] && exit 0
+
+usage ()
+{
+ echo $"Usage: $0 {start|stop|status|restart|condrestart}" 1>&2
+ RETVAL=1
+}
+
+print_address_info ()
+{
+ local host=$1
+ local route via target
+
+ route=$(LANG=C ip -o route get to $host/32)
+
+ [ -z "$DEV" ] && DEV=$(echo $route | sed "s|.* dev \([^ ]*\).*|\1|")
+ echo "DEV=$DEV"
+ echo "LOCALADDR=$(echo $route | sed "s|.* src \([^ ]*\).*|\1|")"
+ if echo $route | grep -q " via " ; then
+ via=$(echo $route | sed "s|.* via \([^ ]*\).*|\1|")
+ target=$via
+ else
+ target=$host
+ fi
+ if [ -z "$SYSLOGMACADDR" ]; then
+ arp=$(LANG=C arping -c 1 -I $DEV $target 2>/dev/null | awk '/ reply from .*[.*]/ { print gensub(".* reply from .* \\[(.*)\\].*","\\1","G") }')
+ [ -n "$arp" ] && echo "SYSLOGMACADDR=$arp"
+ fi
+}
+
+netconsole_failure ()
+{
+ echo -n "$1"
+ failure
+ echo
+ exit 1
+}
+
+start ()
+{
+ SYSLOGOPTS=
+ # syslogd server, if any
+ if ! [[ "$SYSLOGADDR" =~ "^([0-9]{1,3}\.){3}[0-9]{1,3}$" ]]; then
+ SYSLOGADDR=$(LANG=C host $SYSLOGADDR 2>/dev/null | awk '/has address / { print $NF }')
+ fi
+ if [ -z "$SYSLOGADDR" ] ; then
+ echo $"Server address not specified in /etc/sysconfig/netconsole" 1>&2
+ exit 1
+ fi
+ eval $(print_address_info $SYSLOGADDR)
+
+ if [ -z "$SYSLOGMACADDR" ]; then
+ echo $"netconsole: can't resolve MAC address of $SYSLOGADDR" 1>&2
+ netconsole_failure "syslog server address resolution"
+ fi
+
+ SYSLOGOPTS="netconsole=$LOCALPORT@$LOCALADDR/$DEV,$SYSLOGPORT@$SYSLOGADDR/$SYSLOGMACADDR "
+
+ logger -p daemon.info -t netconsole: inserting netconsole module with arguments \
+ $SYSLOGOPTS
+ if [ -n "$SYSLOGOPTS" ]; then
+ action $"Initializing netconsole" modprobe netconsole \
+ $SYSLOGOPTS
+ fi
+ touch /var/lock/subsys/netconsole
+}
+
+stop ()
+{
+ if /sbin/lsmod | grep netconsole >/dev/null 2>&1 ; then
+ action $"Disabling netconsole" rmmod netconsole;
+ fi
+
+ rm -f /var/lock/subsys/netconsole
+}
+
+status ()
+{
+ if /sbin/lsmod | grep netconsole >/dev/null 2>&1 ; then
+ echo $"netconsole module loaded"
+ else
+ echo $"netconsole module not loaded"
+ fi
+}
+
+
+restart ()
+{
+ stop
+ start
+}
+
+condrestart ()
+{
+ [ -e /var/lock/subsys/netconsole ] && restart
+}
+
+
+case "$1" in
+ stop) stop ;;
+ status) status ;;
+ start|restart|reload) restart ;;
+ condrestart) condrestart ;;
+ *) usage ;;
+esac
+
+exit $RETVAL
diff --git a/sysconfig/netconsole b/sysconfig/netconsole
new file mode 100644
index 00000000..7b9d96e5
--- /dev/null
+++ b/sysconfig/netconsole
@@ -0,0 +1,20 @@
+# This is the configuration file for the netconsole service. By starting
+# this service you allow a remote syslog daemon to record console output
+# from this system.
+
+# The local port number that the netconsole module will use
+# LOCALPORT=6666
+
+# The ethernet device to send console messages out of (only set this if it
+# can't be automatically determined)
+# DEV=
+
+# The IP address of the remote syslog server to send messages to
+# SYSLOGADDR=
+
+# The listening port of the remote syslog daemon
+# SYSLOGPORT=514
+
+# The MAC address of the remote syslog server (only set this if it can't
+# be automatically determined)
+# SYSLOGMACADDR=