diff --git a/src/qlever/commands/start.py b/src/qlever/commands/start.py index 4b6ae8f6..57c58900 100644 --- a/src/qlever/commands/start.py +++ b/src/qlever/commands/start.py @@ -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") @@ -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) diff --git a/src/qlever/commands/status.py b/src/qlever/commands/status.py index a8efed54..cd0475a3 100644 --- a/src/qlever/commands/status.py +++ b/src/qlever/commands/status.py @@ -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 @@ -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 diff --git a/src/qlever/commands/stop.py b/src/qlever/commands/stop.py index 82225304..811321d8 100644 --- a/src/qlever/commands/stop.py +++ b/src/qlever/commands/stop.py @@ -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", @@ -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 " @@ -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