boot2docker/boot2docker — pull request #293 by boxofrox (2014-03-22 05:51:11+00:00)
Title: Fix/call opt shutdown script from init

Fixes #289.

#### Changes

##### Update rc.shutdown from make_iso.sh
`make_iso.sh` already extracts TCL's rootfs, so this is where I modify `/etc/init.d/rc.shutdown`. The sed script seems intimidating, but for good reason. I can explain how the sed command works if anyone is interested.

I choose to insert the "test && run" command after `rc.shutdown` completes initialization in case future development decides to display console messages from `shutdown.sh`. Sed will:

1. Insert "test && run" after the `useBusybox` and `clear` lines.
2. Only insert once.

The sed range `1,/^useBusybox/` protects against multiple lines of `useBusybox`—followed by a blank line then followed by `clear`—in `rc.shutdown`, but this may be overkill, because there's no reason for someone to do that. I think the range is a small price to pay, but I can elide this if requested.

##### Fail build if rc.shutdown doesn't change
The previous change is fragile in that, any changes to `rc.shutdown` may break the pattern I use to insert the "test && run" command. If a grep check fails, then the build process stops and prints an error message. This ensures that future changes don't disable the "test && run" command without notice.

##### Update the ACPI power action
We no longer need `exitcheck.sh` here. It does two things: 1) run `/opt/shutdown.sh` and 2) run `/sbin/poweroff`. Leaving it will result in the shutdown script running twice. Calling `/sbin/poweroff` instead.

##### Print a message during shutdown/reboot
The future is here! `/opt/shutdown.sh` will print "Running boot2docker shutdown script..." to the console. I found this useful for testing this changeset.

#### Testing
* Over SSH: Ran `poweroff` and `shutdown` from within a boot2docker VM on VMWare ESXI 5.1. Passed.
* ACPI (I think): Loaded boot2docker in KVM/QEMU, opened qemu-monitor, and ran `system_poweroff`. Passed.
* Build stops with error if `rc.shutdown` does not contain `/opt/shutdown.sh`. Passed.
* Build continues if `/opt/shutdown.sh` was inserted into `rc.shutdown`. Passed.