Skip to content

Commit

Permalink
Try subprocess
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Indenbaum <[email protected]>
  • Loading branch information
Alexander Indenbaum committed Oct 3, 2023
1 parent 6ff60f9 commit 9f04faf
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions control/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import json
import logging
import signal
import threading
import time
from concurrent import futures
from google.protobuf import json_format

Expand Down Expand Up @@ -87,6 +87,12 @@ def __exit__(self, exc_type, exc_value, traceback):
self.logger.info("Stopping the server...")
self.server.stop(None)

if self.discovery_pid:
self.logger.info("Terminating discovery service...")
os.kill(self.discovery_pid, signal.SIGTERM)
time.sleep(0.1) # a bit of grace period before final blow
os.kill(self.discovery_pid, signal.SIGKILL)

self.logger.info("Exiting the gateway process.")

def serve(self):
Expand Down Expand Up @@ -115,25 +121,28 @@ def serve(self):
# Start server
self.server.start()

# Start discovery service
self._start_discovery_service()

def _start_discovery_service(self):
"""Runs either SPDK on CEPH NVMEOF Discovery Service."""
enable_spdk_discovery_controller = self.config.getboolean_with_default("gateway", "enable_spdk_discpovery_controller", False)
if not enable_spdk_discovery_controller:
try:
rpc_nvmf.nvmf_delete_subsystem(self.spdk_rpc_ping_client, "nqn.2014-08.org.nvmexpress.discovery")
except Exception as ex:
self.logger.error(f" Delete Discovery subsystem returned with error: \n {ex}")
raise
if enable_spdk_discovery_controller:
self.logger.info("Using SPDK discovery service")
return

try:
rpc_nvmf.nvmf_delete_subsystem(self.spdk_rpc_ping_client, "nqn.2014-08.org.nvmexpress.discovery")
except Exception as ex:
self.logger.error(f" Delete Discovery subsystem returned with error: \n {ex}")
raise

def discovery_thread():
while True:
try:
DiscoveryService(self.config).start_service()
except:
self.logger.exception("Discovery service exception:")
self.logger.error("Discovery service restarting")

# Start discovery service thread
self.logger.info("Starting ceph nvmeof discovery service thread")
threading.Thread(target=discovery_thread).start()
# run ceph nvmeof discovery service in sub-process
self.discovery_pid = os.fork()
if self.discovery_pid == 0:
self.logger.info("Starting ceph nvmeof discovery service")
DiscoveryService(self.config).start_service()
raise SystemExit

def _add_server_listener(self):
"""Adds listener port to server."""
Expand Down

0 comments on commit 9f04faf

Please sign in to comment.