Skip to contentSkip to conversation

os-posix: call system_powerdown on SIGTERM, enabling clean guest shutdown

PATCH In review Bjørn Mork 2 participants 3 messages Nov 3, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 os-posix: call system_powerdown on SIGTERM, enabling clean guest shutdown

Allow well behaved guests to shutdown cleanly when we receive SIGTERM, e.g. when the host reboots.

The host may be powered down or rebooted while guests are running without any outer supervision scripts. These guests will be stopped by the generic host "sendsigs" script, usually by sending SIGTERM to all processes still running and then SIGKILL if that didn't work. Let the guest power down instead of just killing i instantly.

---
I wonder if I miss something obvious here... So this patch should be considered a RFC. It certainly fixes a small problem for me: I often run a number of guests which are started manually, or by simple "runme" scripts, without any libvirt wrapper or similar. If/when the host is rebooted, these guests will be shut down abrubtly with possible guest file system corruption and other data loss as a consequence. Powering down on SIGTERM seems like an obious win-win.

I also wonder if it would be useful to do a reboot on HUP, but that wouldn't solve any real problem so I'm not including it in this patch.

Bjørn

 os-posix.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
os-posix.c +4 -1
index dbf3b24..167fd3b 100644
@@ -65,7 +65,10 @@ void os_setup_early_signal_handling(void)
 
 static void termsig_handler(int signal, siginfo_t *info, void *c)
 {
-    qemu_system_killed(info->si_signo, info->si_pid);
+    if (info->si_signo == SIGTERM)
+	qemu_system_powerdown_request();
+    else
+	qemu_system_killed(info->si_signo, info->si_pid);
 }
 
 void os_setup_signal_handling(void)
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 10 lines · Bjørn Mork

Allow well behaved guests to shutdown cleanly when we receive SIGTERM, e.g. when the host reboots.

The host may be powered down or rebooted while guests are running without any outer supervision scripts. These guests will be stopped by the generic host "sendsigs" script, usually by sending SIGTERM to all processes still running and then SIGKILL if that didn't work. Let the guest power down instead of just killing i instantly.

I don't think this is such a good idea. SIGTERM shouldn't be subject to the guest's interpretations.

Instead of doing a killall qemu, just send a system_powerdown command to each qemu's monitor instance.

Regards,

Anthony Liguori

Quoted 36 lines

---
I wonder if I miss something obvious here... So this patch should be considered a RFC. It certainly fixes a small problem for me: I often run a number of guests which are started manually, or by simple "runme" scripts, without any libvirt wrapper or similar. If/when the host is rebooted, these guests will be shut down abrubtly with possible guest file system corruption and other data loss as a consequence. Powering down on SIGTERM seems like an obious win-win.

I also wonder if it would be useful to do a reboot on HUP, but that wouldn't solve any real problem so I'm not including it in this patch.

Bjørn

  os-posix.c |    5 ++++-
  1 files changed, 4 insertions(+), 1 deletions(-)
os-posix.c +4 -1
index dbf3b24..167fd3b 100644
@@ -65,7 +65,10 @@ void os_setup_early_signal_handling(void)
 
  static void termsig_handler(int signal, siginfo_t *info, void *c)
  {
-    qemu_system_killed(info->si_signo, info->si_pid);
+    if (info->si_signo == SIGTERM)
+	qemu_system_powerdown_request();
+    else
+	qemu_system_killed(info->si_signo, info->si_pid);
  }
 
  void os_setup_signal_handling(void)
#2 lore raw
Quoted 2 lines · Anthony Liguori

I don't think this is such a good idea. SIGTERM shouldn't be subject to the guest's interpretations.

OK. Just an idea. Thanks for the feedback.

Quoted 2 lines

Instead of doing a killall qemu, just send a system_powerdown command to each qemu's monitor instance.

Yes, I know I should. I am just too lazy to create such scripts for some of the more occasional guests. This does of course reflect their relative importance to me.

Bjørn