blob: b4ead7d595d20bfefc1ce53bfb126aa1f4a67736 [file] [log] [blame]
#!/bin/sh
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Shutdown is best-effort. We don't want to die on errors.
set +e
logevent() {
local event=shutdown-$1
local metricsfile=/var/log/metrics/shutdown_${1}
local metricslist="time read-sectors write-sectors"
bootstat $event
bootstat_get_last $event $metricslist > $metricsfile
}
# Measure shutdown time. /var/log/metrics is created by chromeos_startup.
logevent start
# Sync the system clock to the hardware clock.
HWCLOCK=/sbin/hwclock
${HWCLOCK} --systohc --utc --noadjfile &
. /sbin/killers
# Remount root in case a developer has remounted it rw for some reason.
mount -n -o remount,ro /
# TODO: swapoff as necessary.
# Kill any that may prevent us from unmounting the stateful partition
# or the crypto-home and then unmount. These should be all that we need
# to unmount for a clean shutdown.
kill_with_open_files_on /mnt/stateful_partition /home/chronos
# Unmount our stateful mount points. If any of these fail we do a best-effort
# attempt to touch a /var/log file for future inspection.
/usr/sbin/cryptohome --action=unmount
if [ $? -ne 0 ] ; then
mount > /var/log/shutdown_cryptohome_umount_failure
fi
# join hwclock setting, already in progress. If the job has already been
# finished and reaped, we need to suppress error output. It seems that anything
# on stderr will make the shutdown appear "unclean" from the POV of upstart.
(fg ${HWCLOCK} || /bin/true) 2> /dev/null
# Measure shutdown time
logevent stop
# Signal that the clean shutdown point was reached (or at least as
# close to that point as we can be before stateful is unmounted).
/sbin/crash_reporter --clean_shutdown
# Lazy umount the tmpfs dirs under /var so we can immediately umount it.
umount -n -l /var/tmp /var/run /var/lock
umount -n /var /usr/local /home /mnt/stateful_partition
if [ $? -ne 0 ] ; then
mount > /mnt/stateful_partition/var/log/shutdown_stateful_umount_failure
mount > /var/log/shutdown_stateful_umount_failure
fi
# Just in case something didn't unmount properly above.
sync
# Ensure that we always claim success.
exit 0