[PATCH rest-dbus] Enable systemd socket activation

OpenBMC Patches openbmc-patches at stwcx.xyz
Thu May 26 13:20:51 AEST 2016


From: Brad Bishop <bradleyb at fuzziesquirrel.com>

Optionally use sockets provided by systemd if present.  If not
start normally.

Signed-off-by: Brad Bishop <bradleyb at fuzziesquirrel.com>
---
 rest-dbus | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/rest-dbus b/rest-dbus
index 2fc5316..a830dbf 100644
--- a/rest-dbus
+++ b/rest-dbus
@@ -4,6 +4,7 @@ import dbus
 import BaseHTTPServer
 import SocketServer
 import json
+import socket
 import os
 import sys
 from xml.etree import ElementTree
@@ -345,7 +346,6 @@ class DBusRestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
             response = DBusRestErrorResonse(ex)
 
         response.render(self)
-        self.wfile.close()
 
     def do_POST(self):
         length = int(self.headers.getheader('content-length'))
@@ -356,11 +356,25 @@ class DBusRestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
             response = DBusRestErrorResonse(ex)
 
         response.render(self)
-        self.wfile.close()
 
 
 class HTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer):
-    pass
+    def __init__(self, address, handler):
+        bind = True
+        if os.environ.get('LISTEN_PID', None) == str(os.getpid()):
+            bind = False
+        BaseHTTPServer.HTTPServer.__init__(
+            self, address, handler, bind_and_activate=bind)
+        if bind is True:
+            self.server_bind()
+        else:
+            FIRST_SYSTEMD_SOCKET_FD = 3
+            self.socket = socket.fromfd(
+                FIRST_SYSTEMD_SOCKET_FD,
+                socket.AF_INET,
+                socket.SOCK_STREAM)
+
+        self.server_activate()
 
 if __name__ == '__main__':
     server = HTTPServer(('', 3000), DBusRestHandler)
-- 
2.8.3




More information about the openbmc mailing list