| #!/bin/sh |
| |
| # Copyright (c) 2009 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 |
| |
| # Measure shutdown time. /var/log/metrics is created by chromeos_startup. |
| cut -f 1 -d ' ' /proc/uptime > /var/log/metrics/uptime_shutdown_start |
| cat /sys/block/sda/stat > /var/log/metrics/disk_shutdown_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 |
| cut -f 1 -d ' ' /proc/uptime > /var/log/metrics/uptime_shutdown_stop |
| cat /sys/block/sda/stat > /var/log/metrics/disk_shutdown_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 |