xref: /titanic_52/usr/src/cmd/power/svc-power (revision 98157a7002f4f2cf7978f3084ca5577f0a1d72b2)
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}
70
71case "$1" in
72'start')
73	/usr/sbin/uadmin 3 2 2>/dev/null
74	if [ $? -eq 0 ]; then
75		init_statefile_entry
76	fi
77
78	if [ -x /usr/sbin/pmconfig -a -r /etc/power.conf ]; then
79		/usr/sbin/pmconfig >/dev/console 2>&1
80	fi
81	;;
82
83'stop')
84	if [ -x /usr/sbin/pmconfig ]; then
85		/usr/sbin/pmconfig -r >/dev/null 2>/dev/null
86	fi
87	;;
88
89*)
90	echo "Usage: $0 { start | stop }"
91	exit 1
92	;;
93esac
94exit 0
95