sma: handle SIGINT and SIGTERM signals
If the app is killed with either one of these signals, it'll shutdown gracefully and exit with zero. Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com> Change-Id: I630f9e34c3ccb382c8e1b53d0f589f3ec4d1483b Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11727 Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
This commit is contained in:
parent
add4a7ce26
commit
4ee3d468c7
@ -24,9 +24,11 @@ class StorageManagementAgent(pb2_grpc.StorageManagementAgentServicer):
|
||||
def register_device(self, device_manager):
|
||||
self._devices[device_manager.protocol] = device_manager
|
||||
|
||||
def run(self):
|
||||
def start(self):
|
||||
self._server.start()
|
||||
self._server.wait_for_termination()
|
||||
|
||||
def stop(self):
|
||||
self._server.stop(None)
|
||||
|
||||
def _find_device_by_name(self, name):
|
||||
return self._devices.get(name)
|
||||
|
@ -4,7 +4,9 @@ from argparse import ArgumentParser
|
||||
import importlib
|
||||
import logging
|
||||
import os
|
||||
import signal
|
||||
import sys
|
||||
import threading
|
||||
import yaml
|
||||
|
||||
sys.path.append(os.path.dirname(__file__) + '/../python')
|
||||
@ -72,6 +74,20 @@ def load_plugins(plugins, client):
|
||||
return devices
|
||||
|
||||
|
||||
def run(agent):
|
||||
event = threading.Event()
|
||||
|
||||
def signal_handler(signum, frame):
|
||||
event.set()
|
||||
|
||||
for signum in [signal.SIGTERM, signal.SIGINT]:
|
||||
signal.signal(signum, signal_handler)
|
||||
|
||||
agent.start()
|
||||
event.wait()
|
||||
agent.stop()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(level=os.environ.get('SMA_LOGLEVEL', 'WARNING').upper())
|
||||
|
||||
@ -85,5 +101,4 @@ if __name__ == '__main__':
|
||||
devices += load_plugins(filter(None, os.environ.get('SMA_PLUGINS', '').split(':')),
|
||||
client)
|
||||
register_devices(agent, devices, config)
|
||||
|
||||
agent.run()
|
||||
run(agent)
|
||||
|
Loading…
Reference in New Issue
Block a user