xref: /onnv-gate/usr/src/cmd/power/svc-power (revision 6423:437422a29d3a)
10Sstevel@tonic-gate#!/sbin/sh
20Sstevel@tonic-gate#
30Sstevel@tonic-gate# CDDL HEADER START
40Sstevel@tonic-gate#
50Sstevel@tonic-gate# The contents of this file are subject to the terms of the
65883Smh27603# Common Development and Distribution License (the "License").
75883Smh27603# You may not use this file except in compliance with the License.
80Sstevel@tonic-gate#
90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate# See the License for the specific language governing permissions
120Sstevel@tonic-gate# and limitations under the License.
130Sstevel@tonic-gate#
140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate#
200Sstevel@tonic-gate# CDDL HEADER END
210Sstevel@tonic-gate#
220Sstevel@tonic-gate#
235883Smh27603# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate# Use is subject to license terms.
250Sstevel@tonic-gate#
260Sstevel@tonic-gate#ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate#
280Sstevel@tonic-gate# If the /etc/power.conf file does not have a "statefile" entry
290Sstevel@tonic-gate# to specify the pathname of the cpr statefile, build one and
300Sstevel@tonic-gate# add the line.  We choose the largest of the standard Sun partitions.
310Sstevel@tonic-gate
320Sstevel@tonic-gateinit_statefile_entry() {
330Sstevel@tonic-gate	[ ! -f /etc/power.conf -o ! -w /etc/power.conf ] && return
340Sstevel@tonic-gate
350Sstevel@tonic-gate	# Whitespace regular expression below is [<TAB><SPACE>]
360Sstevel@tonic-gate
370Sstevel@tonic-gate	pattern="^[ 	]*statefile[	 ][	 ]*/"
380Sstevel@tonic-gate	[ `/usr/bin/grep -c "$pattern" /etc/power.conf` -ge 1 ] && return
390Sstevel@tonic-gate
400Sstevel@tonic-gate	avail=0			# Free blocks in current filesystem
410Sstevel@tonic-gate	max_avail=0		# Most available free blocks encountered so far
420Sstevel@tonic-gate 	statefile=.CPR		# Default cpr statefile name
430Sstevel@tonic-gate
440Sstevel@tonic-gate	# Remove old statefile (if any) from root
450Sstevel@tonic-gate	[ -f /$statefile ] && /usr/bin/rm -f /$statefile
460Sstevel@tonic-gate
470Sstevel@tonic-gate	/usr/bin/df -k -F ufs |
480Sstevel@tonic-gate	(
490Sstevel@tonic-gate		read line	# Skip past the header line of the df output
500Sstevel@tonic-gate
510Sstevel@tonic-gate		while read device kbytes used avail capacity filesys; do
520Sstevel@tonic-gate			case $filesys in
530Sstevel@tonic-gate			/|/usr|/var|/export/home)
540Sstevel@tonic-gate				if [ $avail -gt $max_avail ]; then
550Sstevel@tonic-gate					max_avail=$avail
560Sstevel@tonic-gate					winner=$filesys
570Sstevel@tonic-gate				fi
580Sstevel@tonic-gate				;;
590Sstevel@tonic-gate			esac
600Sstevel@tonic-gate		done
610Sstevel@tonic-gate
620Sstevel@tonic-gate		if [ $max_avail -gt 0 ]; then
630Sstevel@tonic-gate			echo "statefile		${winner}/${statefile}" \
640Sstevel@tonic-gate			    >>/etc/power.conf
650Sstevel@tonic-gate		fi
660Sstevel@tonic-gate
670Sstevel@tonic-gate		return
680Sstevel@tonic-gate	)
69*6423Sgw25295	if [ $max_avail -eq 0 ]; then
70*6423Sgw25295		if [ X`df -n / | awk '{print $3}'` != "Xzfs" ] ; then
71*6423Sgw25295			return
72*6423Sgw25295		fi
73*6423Sgw25295		rootpool=`zfs mount | grep ' \/$' | awk '{print $1 }' |\
74*6423Sgw25295		    sed 's/\/.*$//'`
75*6423Sgw25295		if [ X$rootpool = "X" ] || \
76*6423Sgw25295		    [ ! -L /dev/zvol/dsk/$rootpool/dump ]; then
77*6423Sgw25295			return
78*6423Sgw25295		fi
79*6423Sgw25295		echo "statefile /dev/zvol/dsk/$rootpool/dump" \
80*6423Sgw25295			>> /etc/power.conf
81*6423Sgw25295	fi
820Sstevel@tonic-gate}
830Sstevel@tonic-gate
840Sstevel@tonic-gatecase "$1" in
850Sstevel@tonic-gate'start')
865883Smh27603	/usr/sbin/uadmin 3 2 2>/dev/null
875883Smh27603	if [ $? -eq 0 ]; then
880Sstevel@tonic-gate		init_statefile_entry
890Sstevel@tonic-gate	fi
900Sstevel@tonic-gate
910Sstevel@tonic-gate	if [ -x /usr/sbin/pmconfig -a -r /etc/power.conf ]; then
920Sstevel@tonic-gate		/usr/sbin/pmconfig >/dev/console 2>&1
930Sstevel@tonic-gate	fi
940Sstevel@tonic-gate	;;
950Sstevel@tonic-gate
960Sstevel@tonic-gate'stop')
970Sstevel@tonic-gate	if [ -x /usr/sbin/pmconfig ]; then
980Sstevel@tonic-gate		/usr/sbin/pmconfig -r >/dev/null 2>/dev/null
990Sstevel@tonic-gate	fi
1000Sstevel@tonic-gate	;;
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate*)
1030Sstevel@tonic-gate	echo "Usage: $0 { start | stop }"
1040Sstevel@tonic-gate	exit 1
1050Sstevel@tonic-gate	;;
1060Sstevel@tonic-gateesac
1070Sstevel@tonic-gateexit 0
108