Skip to content

Commit

Permalink
Only stop index container if one is actually running (#70)
Browse files Browse the repository at this point in the history
So far, `qlever index` always called `docker rm -f ...` or `podman rm -f ...` before starting a new index build. However, old versions of podman return an error message when no container with the specified name is running. This is now fixed by checking explicitly whether a container is running and only if there is, trying to stop and remove it. Fixes #66.
  • Loading branch information
Qup42 authored Oct 9, 2024
1 parent 8b9c982 commit d935267
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "qlever"
description = "Script for using the QLever SPARQL engine."
version = "0.5.6"
version = "0.5.7"
authors = [
{ name = "Hannah Bast", email = "[email protected]" }
]
Expand Down
13 changes: 8 additions & 5 deletions src/qlever/commands/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,14 @@ def execute(self, args) -> bool:
# Remove already existing container.
if args.system in Containerize.supported_systems() \
and args.overwrite_existing:
try:
run_command(f"{args.system} rm -f {args.index_container}")
except Exception as e:
log.error(f"Removing existing container failed: {e}")
return False
if Containerize.is_running(args.system, args.index_container):
log.info("Another index process is running, trying to stop it ...")
log.info("")
try:
run_command(f"{args.system} rm -f {args.index_container}")
except Exception as e:
log.error(f"Removing existing container failed: {e}")
return False

# Write settings.json file.
try:
Expand Down
12 changes: 12 additions & 0 deletions src/qlever/containerize.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from typing import Optional

from qlever.log import log
from qlever.util import run_command


class ContainerizeException(Exception):
Expand Down Expand Up @@ -78,6 +79,17 @@ def containerize_command(cmd: str, container_system: str,
f" -c {shlex.quote(cmd)}")
return containerized_cmd

@staticmethod
def is_running(container_system: str, container_name: str) -> bool:
# Note: the `{{{{` and `}}}}` result in `{{` and `}}`, respectively.
containers = (
run_command(f"{container_system} ps --format=\"{{{{.Names}}}}\"",
return_output=True)
.strip()
.splitlines()
)
return container_name in containers

@staticmethod
def stop_and_remove_container(container_system: str,
container_name: str) -> bool:
Expand Down

0 comments on commit d935267

Please sign in to comment.