Skip to content
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ start-all.sh
**/.venv*/
**/dist/

**/*.bak
**/*.bak

**/*.pid
2 changes: 1 addition & 1 deletion api/src/makemkv_headless/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

from makemkv_headless.cli.subcommands import (
find_duplicate_media, start, stop
find_duplicate_media, start, stop, status
)
51 changes: 51 additions & 0 deletions api/src/makemkv_headless/cli/subcommands/status.py
Original file line number Diff line number Diff line change
@@ -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'
)
2 changes: 1 addition & 1 deletion api/src/makemkv_headless/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
3 changes: 3 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

uv --project api run mmh "$@"
13 changes: 2 additions & 11 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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