xref: /titanic_41/usr/src/cmd/dumpadm/svc-dumpadm (revision 6a634c9dca3093f3922e4b7ab826d7bdf17bf78e)
17c478bd9Sstevel@tonic-gate#!/sbin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
67950274eSeschrock# Common Development and Distribution License (the "License").
77950274eSeschrock# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
227c478bd9Sstevel@tonic-gate#
23*f6e214c7SGavin Maltby# Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate#
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate. /lib/svc/share/smf_include.sh
27*f6e214c7SGavin Maltby. /lib/svc/share/fs_include.sh
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate#
307c478bd9Sstevel@tonic-gate# mksavedir
317c478bd9Sstevel@tonic-gate# Make sure that $DUMPADM_SAVDIR is set and exists.
327c478bd9Sstevel@tonic-gate#
337c478bd9Sstevel@tonic-gatemksavedir ()
347c478bd9Sstevel@tonic-gate{
357c478bd9Sstevel@tonic-gate	[ -z "$DUMPADM_SAVDIR" ] && DUMPADM_SAVDIR=/var/crash/`uname -n`
367c478bd9Sstevel@tonic-gate	[ -d "$DUMPADM_SAVDIR" ] || /usr/bin/mkdir -m 0700 -p $DUMPADM_SAVDIR
377c478bd9Sstevel@tonic-gate}
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate#
407c478bd9Sstevel@tonic-gate# We haven't run savecore on a dump device yet
417c478bd9Sstevel@tonic-gate#
427c478bd9Sstevel@tonic-gatesavedev=none
437c478bd9Sstevel@tonic-gate
447c478bd9Sstevel@tonic-gate#
457c478bd9Sstevel@tonic-gate# If we previously crashed early in boot before dumpadm was used to configure
467c478bd9Sstevel@tonic-gate# an alternate dump device, then the dump is in the primary swap partition,
477c478bd9Sstevel@tonic-gate# which was configured as the dump device by the first swapadd early in boot.
487c478bd9Sstevel@tonic-gate# Thus before we run dumpadm to configure the dump device, we first run
49*f6e214c7SGavin Maltby# savecore to check the swap partition for a dump;  this is run in the
50*f6e214c7SGavin Maltby# foreground to reduce the chances of overwriting the dump.
517c478bd9Sstevel@tonic-gate#
52*f6e214c7SGavin Maltby# This does not apply for zfs root systems that use a zvol for dump;
53*f6e214c7SGavin Maltby# for such systems the dedicated dump device is appointed during startup
54*f6e214c7SGavin Maltby# of the filesystem/usr:default instance before any swap is added.
55*f6e214c7SGavin Maltby# Therefore we must check that the dump device is a swap device here -
56*f6e214c7SGavin Maltby# if not then we'll run savecore here in the foreground and prevent
57*f6e214c7SGavin Maltby# our dependent services coming online until we're done.
58*f6e214c7SGavin Maltby#
59*f6e214c7SGavin Maltby
60*f6e214c7SGavin Maltbyrootiszfs=0
61*f6e214c7SGavin Maltbyalreadydedicated=0
62*f6e214c7SGavin Maltby
63*f6e214c7SGavin Maltbyreadmnttab / </etc/mnttab
64*f6e214c7SGavin Maltbyif [ "$fstype" = zfs ] ; then
65*f6e214c7SGavin Maltby	rootiszfs=1
66*f6e214c7SGavin Maltby	if [ -x /usr/sbin/dumpadm ]; then
67*f6e214c7SGavin Maltby		if /usr/sbin/dumpadm 2>/dev/null | grep "Dump device:" | \
68*f6e214c7SGavin Maltby		    grep '(dedicated)' > /dev/null 2>&1; then
69*f6e214c7SGavin Maltby			alreadydedicated=1
70*f6e214c7SGavin Maltby		fi
71*f6e214c7SGavin Maltby	fi
72*f6e214c7SGavin Maltbyfi
73*f6e214c7SGavin Maltby
74*f6e214c7SGavin Maltbyif [ -x /usr/bin/savecore -a \
75*f6e214c7SGavin Maltby    \( ! $rootiszfs -eq 1 -o $alreadydedicated -eq 0 \) ]; then
767c478bd9Sstevel@tonic-gate	[ -r /etc/dumpadm.conf ] && . /etc/dumpadm.conf
777c478bd9Sstevel@tonic-gate
787c478bd9Sstevel@tonic-gate	if [ "x$DUMPADM_ENABLE" != xno ] && mksavedir; then
797c478bd9Sstevel@tonic-gate		/usr/bin/savecore $DUMPADM_SAVDIR
807c478bd9Sstevel@tonic-gate		shift $#
817c478bd9Sstevel@tonic-gate		set -- `/usr/sbin/dumpadm 2>/dev/null | /usr/bin/grep 'device:'`
827c478bd9Sstevel@tonic-gate		savedev=${3:-none}
837c478bd9Sstevel@tonic-gate	else
84*f6e214c7SGavin Maltby		#
85*f6e214c7SGavin Maltby		# dumpadm -n is in effect, but we can still run savecore
86*f6e214c7SGavin Maltby		# to raise an event with initial panic detail extracted
87*f6e214c7SGavin Maltby		# from the dump header.
88*f6e214c7SGavin Maltby		#
89*f6e214c7SGavin Maltby		/usr/bin/savecore -c
90*f6e214c7SGavin Maltby	fi
91*f6e214c7SGavin Maltbyfi
92*f6e214c7SGavin Maltby
93*f6e214c7SGavin Maltbyif [ ! -x /usr/bin/savecore ]; then
947c478bd9Sstevel@tonic-gate	echo "WARNING: /usr/bin/savecore is missing or not executable" >& 2
957c478bd9Sstevel@tonic-gatefi
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate#
987c478bd9Sstevel@tonic-gate# Now run dumpadm to configure the dump device based on the settings
997c478bd9Sstevel@tonic-gate# previously saved by dumpadm.  See dumpadm(1m) for instructions on
1007c478bd9Sstevel@tonic-gate# how to modify the dump settings.
1017c478bd9Sstevel@tonic-gate#
1027c478bd9Sstevel@tonic-gateif [ -x /usr/sbin/dumpadm ]; then
1037c478bd9Sstevel@tonic-gate	/usr/sbin/dumpadm -u || $SMF_EXIT_ERR_CONFIG
1047c478bd9Sstevel@tonic-gateelse
1057c478bd9Sstevel@tonic-gate	echo "WARNING: /usr/sbin/dumpadm is missing or not executable" >& 2
1067c478bd9Sstevel@tonic-gate	exit $SMF_EXIT_ERR_CONFIG
1077c478bd9Sstevel@tonic-gatefi
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gateif [ -r /etc/dumpadm.conf ]; then
1107c478bd9Sstevel@tonic-gate	. /etc/dumpadm.conf
1117c478bd9Sstevel@tonic-gateelse
1127c478bd9Sstevel@tonic-gate	echo "WARNING: /etc/dumpadm.conf is missing or unreadable" >& 2
1137c478bd9Sstevel@tonic-gate	exit $SMF_EXIT_ERR_CONFIG
1147c478bd9Sstevel@tonic-gatefi
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate#
117*f6e214c7SGavin Maltby# If the savecore executable is absent then we're done
118*f6e214c7SGavin Maltby#
119*f6e214c7SGavin Maltbyif [ ! -x /usr/bin/savecore ]; then
120*f6e214c7SGavin Maltby	exit $SMF_EXIT_ERR_CONFIG
121*f6e214c7SGavin Maltbyfi
122*f6e214c7SGavin Maltby
123*f6e214c7SGavin Maltby#
1247c478bd9Sstevel@tonic-gate# Now that dumpadm has reconfigured /dev/dump, we need to run savecore again
1257c478bd9Sstevel@tonic-gate# because the dump device may have changed.  If the earlier savecore had
1267c478bd9Sstevel@tonic-gate# saved the dump, savecore will just exit immediately.
1277c478bd9Sstevel@tonic-gate#
128*f6e214c7SGavin Maltby
129*f6e214c7SGavin Maltbyisswap=0
130*f6e214c7SGavin Maltbyswapchanged=0
1317950274eSeschrockif /usr/sbin/swap -l 2>/dev/null | grep "^${DUMPADM_DEVICE} " \
1327950274eSeschrock	    >/dev/null 2>&1; then
133*f6e214c7SGavin Maltby	isswap=1
134*f6e214c7SGavin Maltby	if [ "x$savedev" != "x$DUMPADM_DEVICE" ]; then
135*f6e214c7SGavin Maltby		swapchanged=1
136*f6e214c7SGavin Maltby	fi
137*f6e214c7SGavin Maltbyfi
138*f6e214c7SGavin Maltby
139*f6e214c7SGavin Maltbyif [ "x$DUMPADM_ENABLE" != xno ]; then
140*f6e214c7SGavin Maltby	if [ $isswap -eq 1 ]; then
1417c478bd9Sstevel@tonic-gate		#
1427c478bd9Sstevel@tonic-gate		# If the dump device is part of swap, we only need to run
1437c478bd9Sstevel@tonic-gate		# savecore a second time if the device is different from the
1447c478bd9Sstevel@tonic-gate		# swap device on which we initially ran savecore.
1457c478bd9Sstevel@tonic-gate		#
146*f6e214c7SGavin Maltby		if [ $swapchanged -eq 1 ]; then
1477c478bd9Sstevel@tonic-gate		    mksavedir && /usr/bin/savecore $DUMPADM_SAVDIR &
148*f6e214c7SGavin Maltby		fi
1497c478bd9Sstevel@tonic-gate	else
1507c478bd9Sstevel@tonic-gate		#
1517c478bd9Sstevel@tonic-gate		# The dump device couldn't have been dedicated before we
1527c478bd9Sstevel@tonic-gate		# ran dumpadm, so we must execute savecore again.
1537c478bd9Sstevel@tonic-gate		#
1547c478bd9Sstevel@tonic-gate		mksavedir && /usr/bin/savecore $DUMPADM_SAVDIR &
1557c478bd9Sstevel@tonic-gate	fi
156*f6e214c7SGavin Maltbyelse
157*f6e214c7SGavin Maltby		#
158*f6e214c7SGavin Maltby		# savecore not enabled.  Check whether a valid dump is
159*f6e214c7SGavin Maltby		# present on the device and raise an event to signal that,
160*f6e214c7SGavin Maltby		# but avoid sending a duplicate event from the savecore -c
161*f6e214c7SGavin Maltby		# earlier.
162*f6e214c7SGavin Maltby		#
163*f6e214c7SGavin Maltby		if [ $isswap -eq 0 -o $swapchanged -eq 1 ]; then
164*f6e214c7SGavin Maltby			/usr/bin/savecore -c
165*f6e214c7SGavin Maltby		fi
1667c478bd9Sstevel@tonic-gatefi
1677c478bd9Sstevel@tonic-gate
1687c478bd9Sstevel@tonic-gateexit $SMF_EXIT_OK
169