This document describes why and how Chrome OS devices shut down or reboot.
“Shut down” is a verb. “Shutdown” is a noun.
Shutdown and reboot are initiated on Chrome OS devices through RequestShutdown or RequestRestart D-Bus method calls to powerd. These methods are typically called by Chrome in response to requests from the user, but they can also be invoked by other processes in some cases (e.g. by update_engine to reboot to apply a system update, or by shell scripts in the lab to reboot devices that don't have working network connections).
Both D-Bus methods accept two arguments:
power_manager::RequestShutdownReason or power_manager::RequestRestartReason value from the powerd constants file in system_apipowerd logs both arguments to the current log file within /var/log/power_manager before handling the request; look for messages like these near the end of the file:
[0429/234951:INFO:daemon.cc(1175)] Got RequestShutdown message from :1.62 with reason user-request (UI request from ash)
[0425/211426:INFO:daemon.cc(1046)] Got RequestRestart message from :1.33 with reason system-update (update_engine applying update)
Shutdown and reboot DBus method calls can be triggered in the CLI with:
powerd_dbus_shutdownpowerd_dbus_rebootThese executables send the RequestShutdown or RequestRestart method calls, respectively, and can be used to test powerd or gracefully shutdown/reboot the device.
powerdpowerd may also decide to shut the system down without input from other processes in some cases, including:
In all cases, powerd will also log a terse message just before it shuts down or reboots:
[0429/234952:INFO:daemon.cc(1606)] Shutting down, reason: user-request
[0425/211426:INFO:daemon.cc(1263)] Restarting, reason: system-update
powerd's Daemon class runs powerd_setuid_helper, its setuid-root helper binary, with --action=shut_down or --action=reboot. powerd_setuid_helper runs:
initctl emit --no-wait runlevel RUNLEVEL=<runlevel> SHUTDOWN_REASON=<reason>
to instruct Upstart to either shut down (runlevel 0) or reboot (runlevel 6) the system. The SHUTDOWN_REASON argument contains a short dash-separated string describing the reason for the request.
The Upstart halt job or reboot job is triggered by the runlevel change. This triggers a cascade of other jobs within Upstart's /etc/init directory. The pre-shutdown job logs a message to /var/log/messages to make it easier to see when and why the system shut down or rebooted while examining logs:
2018-04-24T21:30:08.513032-07:00 NOTICE pre-shutdown[22132]: Shutting down for reboot: not-via-powerd
In the above case,
not-via-powerdindicates that this clean reboot was initiated by therebootcommand being run directly rather through powerd. Requests should always go throughpowerdwhen possible, both for consistency and for correctness (e.g.powerdknows to defer shutting down if a firmware update is in progress).
After other jobs have completed, the halt or reboot job executes the chromeos_shutdown script. chromeos_shutdown handles various tasks:
SHUTDOWN_REASON argument with value low-battery, the display_low_battery_alert script is executed to use frecon to display a brief animation before shutting down.Finally, the halt or reboot job executes the halt or reboot command with --force to instruct the kernel to immediately halt or reboot the system.