Skip to content
This repository has been archived by the owner on Nov 29, 2021. It is now read-only.

Stop all running scans before exiting #303

Merged
merged 2 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix get_scanner_details(). [#210](https://github.com/greenbone/ospd/pull/210)
- Fix thread lib leak using daemon mode for python 3.7. [#272](https://github.com/greenbone/ospd/pull/272)
- Fix scan progress in which all hosts are dead or excluded. [#295](https://github.com/greenbone/ospd/pull/295)
- Stop all running scans before exiting [#303](https://github.com/greenbone/ospd/pull/303)
- Fix start of parallel queued task. [#304](https://github.com/greenbone/ospd/pull/304)

### Removed
Expand Down
1 change: 1 addition & 0 deletions ospd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def exit_cleanup(

with pidpath.open() as f:
if int(f.read()) == os.getpid():
LOGGER.debug("Performing exit clean up")
daemon.daemon_exit_cleanup()
LOGGER.info("Shutting-down server ...")
server.close()
Expand Down
19 changes: 19 additions & 0 deletions ospd/ospd.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,25 @@ def daemon_exit_cleanup(self) -> None:
""" Perform a cleanup before exiting """
self.scan_collection.clean_up_pickled_scan_info()

for scan_id in self.scan_collection.ids_iterator():
self.stop_scan(scan_id)

while True:
all_stopped = True
for scan_id in self.scan_collection.ids_iterator():
status = self.get_scan_status(scan_id)
if (
status != ScanStatus.STOPPED
or status != ScanStatus.FINISHED
or status != ScanStatus.INTERRUPTED
):
all_stopped = False

if all_stopped:
return

time.sleep(1)

def get_daemon_name(self) -> str:
""" Gives osp daemon's name. """
return self.daemon_info['name']
Expand Down