#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright 2009 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
# All Rights Reserved
# Sequence performed to change the init state of a machine. Only allows
# transitions to states 0,1,5,6,s,S (i.e.: down or administrative states).
# This procedure checks to see if you are permitted and allows an
# interactive shutdown. The actual change of state, killing of
# processes and such are performed by the new init state, say 0,
echo "Usage: $0 [ -y ] [ -g<grace> ] [ -i<initstate> ] [ message ]"
exit 1
}
notify() {
$*
!
then
if [ "X${remotes}" != "X" ]
then
$*
!
fi
fi
}
# Set the PATH so that to guarentee behavior of shell built in commands
# (such as echo).
# Initial sanity checks:
# Make sure /usr is mounted
# Check the user id (only root can run shutdown)
then
echo "$0: /usr is not mounted. Mount /usr or use init to shutdown."
exit 1
fi
then
then
echo "$0: Only root can run $0"
exit 2
fi
else
echo "$0: can't check user id."
exit 2
fi
# Get options (defaults immediately below):
grace=60
while getopts g:i:y? c
do
case $c in
g)
*[!0-9]* )
echo "$0: -g requires a numeric option"
;;
[0-9]* )
;;
esac
;;
i)
[Ss0156])
;;
[234abcqQ])
echo "$0: Initstate $OPTARG is not for system shutdown"
exit 1
;;
*)
echo "$0: $OPTARG is not a valid initstate"
;;
esac
;;
y)
;;
\?) usage
;;
esac
done
echo '\nShutdown started. \c'
echo
cd /
# If other users are on the system (and any grace period is given), warn them.
then
time=""
then
time="${hours} hours "
then
time="1 hour "
fi
then
time="${time}${minutes} minutes "
then
time="${time}1 minute "
fi
then
then
time="${time}${seconds} second"
else
time="${time}${seconds} seconds"
fi
fi
(notify \
"The system ${NODENAME} will be shut down in ${time}
$*") &
pid1=$!
$*
!
grace=$i
fi
done
# Confirm that we really want to shutdown.
if [ ${askconfirmation} ]
then
echo "Do you want to continue? (y or n): \c"
read b
if [ "$b" != "y" ]
then
notify "False Alarm: The system ${NODENAME} will not be brought down."
echo 'Shutdown aborted.'
exit 1
fi
fi
# Final shutdown message, and sleep away the final 10 seconds (or less).
(notify \
"THE SYSTEM ${NODENAME} IS BEING SHUT DOWN NOW ! ! !
Log off now or risk your files being damaged
$*") &
pid2=$!
then
fi
# Go to the requested initstate.
echo "Changing to init state $initstate - please wait"
then
fi