Add requirements.txt and start/stop/restart background server scripts

This commit is contained in:
david
2026-08-26 09:51:46 -04:00
parent 3b040ca881
commit c51433e9e1
6 changed files with 102 additions and 0 deletions
+2
View File
@@ -9,6 +9,8 @@ __pycache__/
*.py[cod]
*$py.class
*.log
*.pid
# Environments
.env
+9
View File
@@ -36,10 +36,19 @@ An automated, AI-powered media organizer with in-browser video streaming, multi-
- CIFS/SMB share mounted or access to qBittorrent WebUI.
### 2. Start the Server
**Foreground:**
```bash
python3 server.py
```
**Background (Silent Mode):**
```bash
./start.sh # Start in background (logs to server.log)
./stop.sh # Stop running server
./restart.sh # Restart server
```
### 3. Open in Browser
Visit **`http://localhost:8000`** (or your machine's IP on port 8000).
+3
View File
@@ -0,0 +1,3 @@
# Python Standard Library only
# Requires Python >= 3.8
# No external third-party packages required
Executable
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -e
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
"$DIR/stop.sh"
sleep 1
"$DIR/start.sh"
Executable
+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -e
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$DIR"
PID_FILE="$DIR/server.pid"
LOG_FILE="$DIR/server.log"
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if kill -0 "$PID" 2>/dev/null; then
echo "Server is already running with PID $PID."
exit 0
else
rm -f "$PID_FILE"
fi
fi
# Start server in detached session, redirecting output to log file
setsid python3 -u server.py > "$LOG_FILE" 2>&1 < /dev/null &
PID=$!
echo $PID > "$PID_FILE"
# Quick check if it started successfully
sleep 0.5
if kill -0 "$PID" 2>/dev/null; then
echo "Server started successfully (PID $PID)."
echo "Logs: $LOG_FILE"
else
echo "Failed to start server. Check logs: $LOG_FILE"
rm -f "$PID_FILE"
exit 1
fi
Executable
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
set -e
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PID_FILE="$DIR/server.pid"
if [ ! -f "$PID_FILE" ]; then
# Also check if any rogue server.py is running in this dir
PIDS=$(pgrep -f "python3.*server.py" || true)
if [ -z "$PIDS" ]; then
echo "Server is not running."
exit 0
else
echo "PID file not found, but found server process(es): $PIDS. Stopping..."
kill $PIDS 2>/dev/null || true
exit 0
fi
fi
PID=$(cat "$PID_FILE")
if kill -0 "$PID" 2>/dev/null; then
echo "Stopping server (PID $PID)..."
kill "$PID" 2>/dev/null || true
# Wait up to 5 seconds for graceful shutdown
for i in {1..10}; do
if ! kill -0 "$PID" 2>/dev/null; then
break
fi
sleep 0.5
done
# Force kill if still alive
if kill -0 "$PID" 2>/dev/null; then
echo "Force killing server (PID $PID)..."
kill -9 "$PID" 2>/dev/null || true
fi
echo "Server stopped."
else
echo "Server (PID $PID) was not running."
fi
rm -f "$PID_FILE"