summaryrefslogtreecommitdiff
path: root/app-admin/cancd/files/netconsole-init.d
diff options
context:
space:
mode:
authorV3n3RiX <venerix@redcorelinux.org>2018-07-14 21:03:06 +0100
committerV3n3RiX <venerix@redcorelinux.org>2018-07-14 21:03:06 +0100
commit8376ef56580626e9c0f796d5b85b53a0a1c7d5f5 (patch)
tree7681bbd4e8b05407772df40a4bf04cbbc8afc3fa /app-admin/cancd/files/netconsole-init.d
parent30a9caf154332f12ca60756e1b75d2f0e3e1822d (diff)
gentoo resync : 14.07.2018
Diffstat (limited to 'app-admin/cancd/files/netconsole-init.d')
-rw-r--r--app-admin/cancd/files/netconsole-init.d67
1 files changed, 67 insertions, 0 deletions
diff --git a/app-admin/cancd/files/netconsole-init.d b/app-admin/cancd/files/netconsole-init.d
new file mode 100644
index 000000000000..dfb28eb9eac0
--- /dev/null
+++ b/app-admin/cancd/files/netconsole-init.d
@@ -0,0 +1,67 @@
+#!/sbin/openrc-run
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+depend() {
+ need net
+}
+
+start() {
+ checkconfig || return 1
+ if [ -z "${TGT_MAC}" ]; then
+ LC_ALL=C /bin/ping -nq -c 3 "${TGT_IP}" -I "${DEVICE}" 1>/dev/null 2>/dev/null
+ ret=$?
+ # ping worked, try arp
+ if [ $ret -eq 0 ]; then
+ TGT_MAC="$(LC_ALL=C arp -an -i ${DEVICE} ${TGT_IP} |egrep -v 'incomplete|no match' | awk '{print $4}')"
+ fi
+ elif [ "${TGT_MAC}" = "broadcast" ]; then
+ TGT_MAC=''
+ fi
+ ebegin "Starting netconsole ${SRC_IP}:${SRC_PORT}(${DEVICE}) -> ${TGT_IP}:${TGT_PORT} ${TGT_MAC}"
+ # else we use the MAC that we are given
+ modprobe netconsole netconsole=${SRC_PORT}@${SRC_IP}/${DEVICE},${TGT_PORT}@${TGT_IP}/${TGT_MAC}
+ ret=$?
+ [ $ret -eq 0 ] && dmesg -n ${LOGLEVEL}
+ eend $ret
+}
+
+stop() {
+ ebegin "Stopping netconsole"
+ modprobe -r netconsole
+ eend $?
+}
+
+checkconfig() {
+ # kernel uses 15 internally
+ if [ "$LOGLEVEL" -lt 0 -o "${LOGLEVEL}" -gt 15 ]; then
+ eerror "Invalid kernel console loglevel."
+ return 1
+ fi
+
+ if [ "$SRC_PORT" -le 0 ]; then
+ eerror "Invalid source port."
+ return 1
+ fi
+
+ LC_ALL=C ifconfig "${DEVICE}" 1>/dev/null 2>/dev/null
+ ret=$?
+
+ if [ -z "${DEVICE}" -o "${ret}" -gt 0 ]; then
+ eerror "Source device invalid."
+ return 1
+ fi
+
+ if [ "$TGT_PORT" -le 0 ]; then
+ eerror "Invalid target port."
+ return 1
+ fi
+
+ if [ -z "$TGT_IP" ]; then
+ eerror "Unspecified target address."
+ return 1
+ fi
+
+ return 0
+}
+# vim: ts=4 sw=4 sts=4: