From 06c9dd2d9cd2448363403280fdebd399719537da Mon Sep 17 00:00:00 2001 From: enigma0Z <6117628+enigma0Z@users.noreply.github.com> Date: Tue, 21 Apr 2026 10:50:33 -0400 Subject: [PATCH 1/4] ignore pid files --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bdba4d6..a87ceca 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,6 @@ start-all.sh **/.venv*/ **/dist/ -**/*.bak \ No newline at end of file +**/*.bak + +**/*.pid \ No newline at end of file From 8454b82d894416727e60e9da2040457ba62bbd71 Mon Sep 17 00:00:00 2001 From: enigma0Z <6117628+enigma0Z@users.noreply.github.com> Date: Tue, 21 Apr 2026 10:50:51 -0400 Subject: [PATCH 2/4] Add run.sh, remove screen run mode --- run.sh | 3 +++ start.sh | 13 ++----------- 2 files changed, 5 insertions(+), 11 deletions(-) create mode 100755 run.sh diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..cba9ad8 --- /dev/null +++ b/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +uv --project api run mmh "$@" \ No newline at end of file diff --git a/start.sh b/start.sh index 7b7511c..a74c226 100755 --- a/start.sh +++ b/start.sh @@ -5,22 +5,13 @@ DEV="false" API_PORT="" WEB_PORT="" -if [[ "$1" == "screen" ]]; then - SCREEN="true"; shift - API_PORT="$1"; shift -fi - if [[ "$1" == "dev" ]]; then DEV="true"; shift API_PORT="$1"; shift WEB_PORT="$1"; shift fi -if [[ "$SCREEN" == "true" ]]; then - set -x - screen -dmS mmh-api-$API_PORT uv --project api run mmh start --listen-port $API_PORT "$@" - set +x -elif [[ "$DEV" == "true" ]]; then +if [[ "$DEV" == "true" ]]; then WEB_PID="" API_PID="" cleanup() { @@ -47,5 +38,5 @@ elif [[ "$DEV" == "true" ]]; then wait $API_PID wait $WEB_PID else - uv --project api run mmh start "$@" + ./run.sh start "$@" fi From e56adf6b5a35133d7ea8c4fd5cb4459ee6fd6235 Mon Sep 17 00:00:00 2001 From: enigma0Z <6117628+enigma0Z@users.noreply.github.com> Date: Tue, 21 Apr 2026 10:51:05 -0400 Subject: [PATCH 3/4] Update help for pid file arg --- api/src/makemkv_headless/models/config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/src/makemkv_headless/models/config.py b/api/src/makemkv_headless/models/config.py index 4b20e3b..f08c6a5 100644 --- a/api/src/makemkv_headless/models/config.py +++ b/api/src/makemkv_headless/models/config.py @@ -145,7 +145,7 @@ class ConfigModel(BaseModel): cli_argument=CliArgument( args=['--pid-file'], kwargs=ParserKwargs( - help="The path to the file to store the pid (if --daemon is used)" + help="The path to the pid file (if --daemon is/was used)" ) ) ).model_dump()) From 35ff2b667dc6ed2f9e9f4621026bb3101aa14b17 Mon Sep 17 00:00:00 2001 From: enigma0Z <6117628+enigma0Z@users.noreply.github.com> Date: Tue, 21 Apr 2026 10:51:17 -0400 Subject: [PATCH 4/4] [minor] Add status subcommand --- api/src/makemkv_headless/cli/__init__.py | 2 +- .../cli/subcommands/status.py | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 api/src/makemkv_headless/cli/subcommands/status.py diff --git a/api/src/makemkv_headless/cli/__init__.py b/api/src/makemkv_headless/cli/__init__.py index 9e387a8..c3a6900 100644 --- a/api/src/makemkv_headless/cli/__init__.py +++ b/api/src/makemkv_headless/cli/__init__.py @@ -1,4 +1,4 @@ from makemkv_headless.cli.subcommands import ( - find_duplicate_media, start, stop + find_duplicate_media, start, stop, status ) \ No newline at end of file diff --git a/api/src/makemkv_headless/cli/subcommands/status.py b/api/src/makemkv_headless/cli/subcommands/status.py new file mode 100644 index 0000000..8c4269e --- /dev/null +++ b/api/src/makemkv_headless/cli/subcommands/status.py @@ -0,0 +1,51 @@ + +from argparse import Namespace +from signal import SIGTERM +from sys import argv + +from os import SEEK_CUR, SEEK_END, kill, unlink +from os.path import basename, exists + +from makemkv_headless.cli.parsers import subparsers +from makemkv_headless.config import CONFIG + +def main(opts: Namespace): + CONFIG.load(opts) + + try: + with open(CONFIG.pid_file, 'r') as pid_file: + pid = int(pid_file.readline()) + kill(pid, 0) + print('Status: Running') + if opts.tail_log is not None and exists(CONFIG.log_file): + with open(CONFIG.log_file, 'rb') as log_file: + num_lines = 10 + log_file.seek(-2, SEEK_END) + try: + while (num_lines > 0): + if (log_file.read(1) == b'\n'): + num_lines -= 1 + + log_file.seek(-2, SEEK_CUR) + except OSError: + pass + + log_file.seek(2, SEEK_CUR) + tail_lines = ''.join([line.decode() for line in log_file.readlines()]) + print('---') + print(tail_lines) + except ProcessLookupError: + print(f'Status: Stopped') + except FileNotFoundError: + print(f'Could not locate pid file {CONFIG.pid_file}') + +parser = subparsers.add_parser('status', help='Display status of the configured makemkv headless') +parser.set_defaults(func=main) + +CONFIG.initialize_parser(parser, ['config_file', 'pid_file']) +parser.add_argument( + '--tail-log', '-t', + nargs=1, + metavar='TAIL_LINES', + help='Print this many log lines from the configured log file' +) \ No newline at end of file