svc-power revision e7cbe64f7a72dae5cb44f100db60ca88f3313c65
2516N/A#!/sbin/sh
2825N/A#
2825N/A# CDDL HEADER START
2516N/A#
2516N/A# The contents of this file are subject to the terms of the
2516N/A# Common Development and Distribution License (the "License").
2516N/A# You may not use this file except in compliance with the License.
2516N/A#
2516N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2516N/A# or http://www.opensolaris.org/os/licensing.
2516N/A# See the License for the specific language governing permissions
2516N/A# and limitations under the License.
2516N/A#
2516N/A# When distributing Covered Code, include this CDDL HEADER in each
2825N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2516N/A# If applicable, add the following below this CDDL HEADER, with the
2516N/A# fields enclosed by brackets "[]" replaced with your own identifying
2516N/A# information: Portions Copyright [yyyy] [name of copyright owner]
2516N/A#
2516N/A# CDDL HEADER END
2825N/A#
2516N/A#
2516N/A# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
2516N/A# Use is subject to license terms.
2516N/A#
2516N/A#ident "%Z%%M% %I% %E% SMI"
2825N/A#
2516N/A# If the /etc/power.conf file does not have a "statefile" entry
2516N/A# to specify the pathname of the cpr statefile, build one and
2516N/A# add the line. We choose the largest of the standard Sun partitions.
2516N/A
2516N/Ainit_statefile_entry() {
2516N/A [ ! -f /etc/power.conf -o ! -w /etc/power.conf ] && return
2516N/A
2516N/A # Whitespace regular expression below is [<TAB><SPACE>]
2516N/A
2516N/A pattern="^[ ]*statefile[ ][ ]*/"
2516N/A [ `/usr/bin/grep -c "$pattern" /etc/power.conf` -ge 1 ] && return
2516N/A
2516N/A avail=0 # Free blocks in current filesystem
2516N/A max_avail=0 # Most available free blocks encountered so far
2516N/A statefile=.CPR # Default cpr statefile name
2516N/A
2516N/A # Remove old statefile (if any) from root
2825N/A [ -f /$statefile ] && /usr/bin/rm -f /$statefile
2516N/A
2516N/A /usr/bin/df -k -F ufs |
2516N/A (
2516N/A read line # Skip past the header line of the df output
2516N/A
2516N/A while read device kbytes used avail capacity filesys; do
2516N/A case $filesys in
2516N/A /|/usr|/var|/export/home)
2516N/A if [ $avail -gt $max_avail ]; then
2516N/A max_avail=$avail
2516N/A winner=$filesys
2516N/A fi
2516N/A ;;
2516N/A esac
2516N/A done
2516N/A
2516N/A if [ $max_avail -gt 0 ]; then
2516N/A echo "statefile ${winner}/${statefile}" \
2516N/A >>/etc/power.conf
2516N/A fi
2516N/A
2516N/A return
2516N/A )
2516N/A if [ $max_avail -eq 0 ]; then
2516N/A if [ X`df -n / | awk '{print $3}'` != "Xzfs" ] ; then
2516N/A return
2516N/A fi
2516N/A rootpool=`zfs mount | grep ' \/$' | awk '{print $1 }' |\
2516N/A sed 's/\/.*$//'`
2516N/A if [ X$rootpool = "X" ] || \
2516N/A [ ! -L /dev/zvol/dsk/$rootpool/dump ]; then
2516N/A return
2516N/A fi
2516N/A echo "statefile /dev/zvol/dsk/$rootpool/dump" \
2516N/A >> /etc/power.conf
2516N/A fi
2516N/A}
2516N/A
2516N/Acase "$1" in
2516N/A'start')
2516N/A /usr/sbin/uadmin 3 2 2>/dev/null
2516N/A if [ $? -eq 0 ]; then
2516N/A init_statefile_entry
2516N/A fi
2516N/A
2516N/A if [ -x /usr/sbin/pmconfig -a -r /etc/power.conf ]; then
2516N/A /usr/sbin/pmconfig >/dev/console 2>&1
2516N/A fi
2516N/A ;;
2825N/A
2825N/A'stop')
2825N/A if [ -x /usr/sbin/pmconfig ]; then
2825N/A /usr/sbin/pmconfig -r >/dev/null 2>/dev/null
2825N/A fi
2825N/A ;;
2825N/A
2825N/A*)
2825N/A echo "Usage: $0 { start | stop }"
2825N/A exit 1
2825N/A ;;
2825N/Aesac
2825N/Aexit 0
2825N/A