I just committed some updates to how Nerves handles power off and
reboot. This was instigated by needing to get ACPI power off working
on x86, but the changes apply to all platforms. Here's how things
currently work:
When the Erlang VM exits, the board is rebooted. This is done
automatically since it is expected that applications are long running
and that an exit is most likely a mistake. Of course, if you
intentionally want to reboot the board, you can always invoke
init:stop/0.
The standard way of rebooting or powering off, though, is to send Unix
signals to the init process. In Nerves, the init process is erlinit.
It behaves similar to standard init implementations except that its
behavior is not configurable. When it gets signalled, it sends SIGTERM
to all OS processes and then sends SIGKILL to any that remain after a
second. After processes are killed, a best effort attempt to sync and
unmount filesystems is made before rebooting or shutting down for
real. Sending SIGUSR1 to erlinit (OS PID 1) halts the processor,
SIGTERM reboots, and SIGUSR2 powers off. The poweroff, halt and reboot
command line utilities will send these signals, so if you run
os:cmd("poweroff"), it will do the right thing.
Frank
--
Frank Hunleth
Troodon Software LLC
Embedded Software Development
http://troodon-software.com/