From 68b1587adafbd15fe47d8b7cd652073dbd06b25f Mon Sep 17 00:00:00 2001
From: Abhishek Kekane <abhishek.kekane@nttdata.com>
Date: Wed, 3 Feb 2016 22:58:21 -0800
Subject: [PATCH] Make websockify respect SIGTERM

Child processes were not terminated when the parent websockify
was killed.

This commit makes websockify send a SIGTERM to all active children
when the parent process is terminated.

Fixes #138
---
 websockify/websocket.py | 8 ++++++++
 1 file changed, 8 insertions(+)

Origin: upstream, https://github.com/novnc/websockify/pull/226
Bug-Ubuntu: https://bugs.launchpad.net/bugs/1715254
Index: websockify-0.6.1+dfsg1/websockify/websocket.py
===================================================================
--- websockify-0.6.1+dfsg1.orig/websockify/websocket.py
+++ websockify-0.6.1+dfsg1/websockify/websocket.py
@@ -1018,6 +1018,14 @@ class WebSocketServer(object):
 
                     except (self.Terminate, SystemExit, KeyboardInterrupt):
                         self.msg("In exit")
+                        # terminate all child processes
+                        if multiprocessing and not self.run_once:
+                            children = multiprocessing.active_children()
+
+                            for child in children:
+                                self.msg("Terminating child %s" % child.pid)
+                                child.terminate()
+
                         break
                     except Exception:
                         self.msg("handler exception: %s", str(exc))
