[CRIU] [PATCH 2/3] p.haul: add --port option to p.haul-service

Ruslan Kuprieiev kupruser at gmail.com
Mon Oct 27 14:18:48 PDT 2014


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

diff --git a/p.haul-service b/p.haul-service
index 7444df5..62225c8 100755
--- a/p.haul-service
+++ b/p.haul-service
@@ -3,15 +3,23 @@
 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("-p", "--port", help = "port to bind on", default = xem_rpc.rpc_port, type = int)
+
+	args = vars(parser.parse_args())
+
+	host = ("0.0.0.0", args.pop("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 71ca051..6665760 100644
--- a/xem_rpc.py
+++ b/xem_rpc.py
@@ -124,9 +124,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)
@@ -149,10 +149,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):
@@ -187,9 +187,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