2

When you terminate an instance-store pv instance through the AWS console or the API, what "signal" does it receive so it knows it has to gracefully shut down?

First guess would be ACPI, but on boot Linux reports

ACPI in unprivileged domain disabled
ACPI: Interpreter disabled.
Axel Fontaine
  • 202
  • 2
  • 10

2 Answers2

6

EC2 uses Xen. The Xen PV driver handles the shutdown. If you were using an HVM instance, ACPI would handle the shutdown.

Mark Wagner
  • 18,019
  • 2
  • 32
  • 47
  • Which PV Driver is that (kernel config option)? – Axel Fontaine Mar 27 '14 at 18:06
  • 1
    CONFIG_XEN is the config option. In the source code see arch/x86/xen/enlighten.c. – Mark Wagner Mar 27 '14 at 19:06
  • Ok, but how does user-space become aware of that then? I take it acpid won't see these events. – Axel Fontaine Mar 27 '14 at 19:23
  • 5
    When a domU boots it registers a watch for "control/shutdown" key in the XenStore with the callback function "shutdown_handler()." In that function orderly_poweroff() is called which in turn calls call_usermodehelper_exec() which executes the command in the variable "poweroff_cmd" which is...wait for it.../sbin/poweroff. This rabbit hole starts here: http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/drivers/xen/manage.c#L229 – Mark Wagner Mar 27 '14 at 20:07
  • I can't upvote this enough. Thank you so much Mark! I would never have found this without your help! – Axel Fontaine Mar 28 '14 at 09:47
2

The command that will be run can be seen by running:

sysctl kernel.poweroff_cmd

And can be changed by running (as root):

sysctl kernel.poweroff_cmd="/usr/bin/systemctl poweroff"

Which can be made permanent on a modern systemd based system by:

cat << EOF > /etc/sysctl.d/poweroff.conf kernel.poweroff_cmd = "/usr/bin/systemctl poweroff" EOF

@Mark Wagner explained it, but the sysctl aspect wasn't clear to me!

daaku
  • 211
  • 1
  • 7