Commit 4ee3d468 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

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: default avatarKonrad 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: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
parent add4a7ce
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -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)
+17 −2
Original line number Diff line number Diff line
@@ -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)