Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle non-default binary name #102

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/qlever/commands/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ def execute(self, args) -> bool:
# TODO: This is currently disabled because I never used it once over
# the past weeks and it is not clear to me what the use case is.
if False: # or args.kill_existing_with_same_name:
args.cmdline_regex = f"^ServerMain.* -i {args.name}"
args.cmdline_regex = f"^{args.server_binary}.* -i {args.name}"
args.no_containers = True
StopCommand().execute(args)
log.info("")

# Kill existing server on the same port if so desired.
if args.kill_existing_with_same_port:
args.cmdline_regex = f"^ServerMain.* -p {args.port}"
args.cmdline_regex = f"^{args.server_binary}.* -p {args.port}"
args.no_containers = True
if not StopCommand().execute(args):
log.error("Stopping the existing server failed")
Expand Down Expand Up @@ -141,7 +141,7 @@ def execute(self, args) -> bool:
"--kill-existing-with-same-port`")

# Show output of status command.
args.cmdline_regex = f"^ServerMain.* -p *{port}"
args.cmdline_regex = f"^{args.server_binary}.* -p *{port}"
log.info("")
StatusCommand().execute(args)

Expand Down
19 changes: 15 additions & 4 deletions src/qlever/commands/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,29 @@ def should_have_qleverfile(self) -> bool:
return False

def relevant_qleverfile_arguments(self) -> dict[str: list[str]]:
return {}
return {"server": ["server_binary"], "index": ["index_binary"]}

def additional_arguments(self, subparser) -> None:
subparser.add_argument("--cmdline-regex",
default="^(ServerMain|IndexBuilderMain)",
default="^(%%SERVER_BINARY%%|%%INDEX_BINARY%%)",
help="Show only processes where the command "
"line matches this regex")

def execute(self, args) -> bool:
cmdline_regex = args.cmdline_regex
# Other commands call status with a custom `cmdline_regex` that contains
# less or no variables. Doing the replacement on-demand has the benefit
# that only the variables that are actually used have to be provided by
# the calling command. For example: the `cmdline_regex` used by start
# has no variables and requiring the index binary for it would be strange.
if "%%SERVER_BINARY%%" in cmdline_regex:
cmdline_regex = cmdline_regex.replace("%%SERVER_BINARY%%", args.server_binary)
if "%%INDEX_BINARY%%" in cmdline_regex:
cmdline_regex = cmdline_regex.replace("%%INDEX_BINARY%%", args.index_binary)

# Show action description.
self.show(f"Show all processes on this machine where "
f"the command line matches {args.cmdline_regex}"
f"the command line matches {cmdline_regex}"
f" using Python's psutil library", only_show=args.show)
if args.show:
return True
Expand All @@ -41,7 +52,7 @@ def execute(self, args) -> bool:
num_processes_found = 0
for proc in psutil.process_iter():
show_heading = num_processes_found == 0
process_shown = show_process_info(proc, args.cmdline_regex,
process_shown = show_process_info(proc, cmdline_regex,
show_heading=show_heading)
if process_shown:
num_processes_found += 1
Expand Down
7 changes: 4 additions & 3 deletions src/qlever/commands/stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def should_have_qleverfile(self) -> bool:

def relevant_qleverfile_arguments(self) -> dict[str: list[str]]:
return {"data": ["name"],
"server": ["port"],
"server": ["server_binary", "port"],
"runtime": ["server_container"]}

def additional_arguments(self, subparser) -> None:
subparser.add_argument("--cmdline-regex",
default="ServerMain.* -i [^ ]*%%NAME%%",
default="%%SERVER_BINARY%%.* -i [^ ]*%%NAME%%",
help="Show only processes where the command "
"line matches this regex")
subparser.add_argument("--no-containers", action="store_true",
Expand All @@ -43,6 +43,7 @@ def additional_arguments(self, subparser) -> None:
def execute(self, args) -> bool:
# Show action description.
cmdline_regex = args.cmdline_regex.replace("%%NAME%%", args.name)
cmdline_regex = cmdline_regex.replace("%%SERVER_BINARY%%", args.server_binary)
description = f"Checking for processes matching \"{cmdline_regex}\""
if not args.no_containers:
description += (f" and for Docker container with name "
Expand Down Expand Up @@ -95,7 +96,7 @@ def execute(self, args) -> bool:
message = "No matching process found" if args.no_containers else \
"No matching process or container found"
log.error(message)
args.cmdline_regex = "^ServerMain.* -i [^ ]*"
args.cmdline_regex = f"^{args.server_binary}.* -i [^ ]*"
log.info("")
StatusCommand().execute(args)
return True