xref: /titanic_50/usr/src/cmd/power/svc-power (revision 895ca178e38ac3583d0c0d8317d51dc5f388df6e)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22#
23# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24# Use is subject to license terms.
25#
26#ident	"%Z%%M%	%I%	%E% SMI"
27#
28# If the /etc/power.conf file does not have a "statefile" entry
29# to specify the pathname of the cpr statefile, build one and
30# add the line.  We choose the largest of the standard Sun partitions.
31
32init_statefile_entry() {
33	[ ! -f /etc/power.conf -o ! -w /etc/power.conf ] && return
34
35	# Whitespace regular expression below is [<TAB><SPACE>]
36
37	pattern="^[ 	]*statefile[	 ][	 ]*/"
38	[ `/usr/bin/grep -c "$pattern" /etc/power.conf` -ge 1 ] && return
39
40	avail=0			# Free blocks in current filesystem
41	max_avail=0		# Most available free blocks encountered so far
42 	statefile=.CPR		# Default cpr statefile name
43
44	# Remove old statefile (if any) from root
45	[ -f /$statefile ] && /usr/bin/rm -f /$statefile
46
47	/usr/bin/df -k -F ufs |
48	(
49		read line	# Skip past the header line of the df output
50
51		while read device kbytes used avail capacity filesys; do
52			case $filesys in
53			/|/usr|/var|/export/home)
54				if [ $avail -gt $max_avail ]; then
55					max_avail=$avail
56					winner=$filesys
57				fi
58				;;
59			esac
60		done
61
62		if [ $max_avail -gt 0 ]; then
63			echo "statefile		${winner}/${statefile}" \
64			    >>/etc/power.conf
65		fi
66
67		return
68	)
69	if [ $max_avail -eq 0 ]; then
70		if [ X`df -n / | awk '{print $3}'` != "Xzfs" ] ; then
71			return
72		fi
73		rootpool=`zfs mount | grep ' \/$' | awk '{print $1 }' |\
74		    sed 's/\/.*$//'`
75		if [ X$rootpool = "X" ] || \
76		    [ ! -L /dev/zvol/dsk/$rootpool/dump ]; then
77			return
78		fi
79		echo "statefile /dev/zvol/dsk/$rootpool/dump" \
80			>> /etc/power.conf
81	fi
82}
83
84case "$1" in
85'start')
86	/usr/sbin/uadmin 3 2 2>/dev/null
87	if [ $? -eq 0 ]; then
88		init_statefile_entry
89	fi
90
91	if [ -x /usr/sbin/pmconfig -a -r /etc/power.conf ]; then
92		/usr/sbin/pmconfig >/dev/console 2>&1
93	fi
94	;;
95
96'stop')
97	if [ -x /usr/sbin/pmconfig ]; then
98		/usr/sbin/pmconfig -r >/dev/null 2>/dev/null
99	fi
100	;;
101
102*)
103	echo "Usage: $0 { start | stop }"
104	exit 1
105	;;
106esac
107exit 0
108