blob: da4181aa21bc4111ce09b84e9ce8a0eee8d56717 [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 --systohc --utc --noadjfile &
HWCLOCK_PID=$!
. /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 /var
# join hwclock setting, already in progress.
wait $HWCLOCK_PID
# 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/run /var/lock
if [ -e /dev/mapper/encstateful ]; then
mount-encrypted umount >/tmp/umount-encrypted.log 2>&1
if [ $? -ne 0 ] ; then
mv /tmp/umount-encrypted.log /mnt/stateful_partition/
fi
umount -n /usr/local /home /mnt/stateful_partition
rc=$?
else
umount -n /var /usr/local /home /mnt/stateful_partition
rc=$?
fi
if [ $rc -ne 0 ] ; then
mount > /mnt/stateful_partition/shutdown_stateful_umount_failure
fi
# Just in case something didn't unmount properly above.
sync
# Display low battery icon if shutting down due to low battery.
# SHUTDOWN_REASON is passed in with the runlevel event from power manager.
if [ "$SHUTDOWN_REASON" = "low-battery" ]; then
display_low_battery_alert
fi
# Ensure that we always claim success.
exit 0