From 57edd68e57e89445a9b4fc714e8fb71bd422d05c Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Thu, 23 Jul 2020 14:11:59 +0200 Subject: [PATCH 1/3] Do the daemon exit cleanup just once from the main process --- ospd/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ospd/main.py b/ospd/main.py index fe7a37de..b0b0aac6 100644 --- a/ospd/main.py +++ b/ospd/main.py @@ -72,13 +72,12 @@ def exit_cleanup( signal.signal(signal.SIGINT, signal.SIG_IGN) pidpath = Path(pidfile) - daemon.daemon_exit_cleanup() - if not pidpath.is_file(): return with pidpath.open() as f: if int(f.read()) == os.getpid(): + daemon.daemon_exit_cleanup() LOGGER.info("Shutting-down server ...") server.close() LOGGER.debug("Finishing daemon process") From 75e835bdb94a378df60bc671d5607a0f47fb3078 Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Thu, 23 Jul 2020 14:12:58 +0200 Subject: [PATCH 2/3] Handle SIGINT in a clean way, when the daemon runs in foreground As the daemoin running in foreground is normally stopped with ctrl+c Now the pid file is removed as expected. --- ospd/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ospd/main.py b/ospd/main.py index b0b0aac6..23276965 100644 --- a/ospd/main.py +++ b/ospd/main.py @@ -143,7 +143,9 @@ def main( signal.signal( signal.SIGTERM, partial(exit_cleanup, args.pid_file, server, daemon) ) - + signal.signal( + signal.SIGINT, partial(exit_cleanup, args.pid_file, server, daemon) + ) if not daemon.check(): return 1 From 59fed2b62d8dcee715638e54dde979ef163e0acb Mon Sep 17 00:00:00 2001 From: Juan Jose Nicola Date: Thu, 23 Jul 2020 14:17:34 +0200 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 332bd1f8..c7c373c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Make scan_id attribute mandatory for get_scans. [#270](https://github.com/greenbone/ospd/pull/270) - Ignore subsequent SIGINT once inside exit_cleanup(). [#273](https://github.com/greenbone/ospd/pull/273) - Simplify start_scan() [#275](https://github.com/greenbone/ospd/pull/275) +- Make ospd-openvas to shut down gracefully [#302](https://github.com/greenbone/ospd/pull/302) ### Fixed - Fix stop scan. Wait for the scan process to be stopped before delete it from the process table. [#204](https://github.com/greenbone/ospd/pull/204)