[CRIU] [PATCH 1/2] p.haul: add --bind-port and --bind-addr to p.haul-service

Ruslan Kuprieiev kupruser at gmail.com
Thu Nov 6 16:43:05 PST 2014


Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 p.haul-service | 11 ++++++++++-
 xem_rpc.py     | 12 ++++++------
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/p.haul-service b/p.haul-service
index cdeff54..0fd52c2 100755
--- a/p.haul-service
+++ b/p.haul-service
@@ -3,15 +3,24 @@
 import signal
 import xem_rpc
 import p_haul_service as ph_srv
+import argparse
 
 if __name__ == "__main__":
+	parser = argparse.ArgumentParser("Process HAULer service server")
+	parser.add_argument("--bind-addr", help = "IP to bind to", type = str, default = "0.0.0.0")
+	parser.add_argument("--bind-port", help = "Port to bind to", type = int, default = xem_rpc.rpc_port)
+
+	args = vars(parser.parse_args())
+
+	host = (args.pop("bind_addr"), args.pop("bind_port"))
+
 	sfd = None
 	def fin(foo, bar):
 		print "Stop by %d" % foo
 		sfd.close()
 
 	print "Starting p.haul rpyc service"
-	t = xem_rpc.rpc_threaded_srv(ph_srv.phaul_service)
+	t = xem_rpc.rpc_threaded_srv(ph_srv.phaul_service, host)
 
 	# FIXME: Setup stop handlers
 	sfd = t.get_stop_fd()
diff --git a/xem_rpc.py b/xem_rpc.py
index 8bbdac7..34aab9b 100644
--- a/xem_rpc.py
+++ b/xem_rpc.py
@@ -121,9 +121,9 @@ class _rpc_server_sk:
 			self._master.on_socket_open(sk._sk, uname)
 
 class _rpc_server_ask:
-	def __init__(self):
+	def __init__(self, host):
 		sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-		sk.bind(("0.0.0.0", rpc_port))
+		sk.bind(host)
 		sk.listen(8)
 		self._sk = sk
 		util.set_cloexec(self)
@@ -146,10 +146,10 @@ class _rpc_stop_fd:
 		mgr.stop()
 
 class _rpc_server_manager:
-	def __init__(self, srv_class):
+	def __init__(self, srv_class, host):
 		self._srv_class = srv_class
 		self._sk_by_name = {}
-		self._poll_list = [_rpc_server_ask()]
+		self._poll_list = [_rpc_server_ask(host)]
 		self._alive = True
 
 	def add(self, sk):
@@ -184,9 +184,9 @@ class _rpc_server_manager:
 		print "RPC Service stops"
 
 class rpc_threaded_srv(threading.Thread):
-	def __init__(self, srv_class):
+	def __init__(self, srv_class, host):
 		threading.Thread.__init__(self)
-		self._mgr = _rpc_server_manager(srv_class)
+		self._mgr = _rpc_server_manager(srv_class, host)
 		self._stop_fd = None
 
 	def run(self):
-- 
1.9.3



More information about the CRIU mailing list