mirror of
https://github.com/acedanger/shell.git
synced 2025-12-06 00:00:13 -08:00
feat: Add comprehensive Plex recovery validation script
- Introduced `validate-plex-recovery.sh` for validating Plex database recovery. - Implemented checks for service status, database integrity, web interface accessibility, API functionality, and recent logs. - Added detailed recovery summary and next steps for users. fix: Improve Debian patching script for compatibility - Enhanced `debian-patches.sh` to securely download and execute bootstrap scripts. - Updated package mapping logic and ensured proper permissions for patched files. fix: Update Docker test scripts for better permission handling - Modified `run-docker-tests.sh` to set appropriate permissions on logs directory. - Ensured log files have correct permissions after test runs. fix: Enhance setup scripts for secure installations - Updated `setup.sh` to securely download and execute installation scripts for zoxide and nvm. - Improved error handling for failed downloads. fix: Refine startup script for log directory permissions - Adjusted `startup.sh` to set proper permissions for log directories and files. chore: Revamp update-containers.sh for better error handling and logging - Rewrote `update-containers.sh` to include detailed logging and error handling. - Added validation for Docker image names and improved overall script robustness.
This commit is contained in:
83
plex/plex.sh
83
plex/plex.sh
@@ -1,5 +1,50 @@
|
||||
#!/bin/bash
|
||||
|
||||
################################################################################
|
||||
# Plex Media Server Management Script
|
||||
################################################################################
|
||||
#
|
||||
# Author: Peter Wood <peter@peterwood.dev>
|
||||
# Description: Modern, user-friendly Plex Media Server management script with
|
||||
# styled output and comprehensive service control capabilities.
|
||||
# Provides an interactive interface for common Plex operations.
|
||||
#
|
||||
# Features:
|
||||
# - Service start/stop/restart/status operations
|
||||
# - Web interface launcher
|
||||
# - Styled console output with Unicode symbols
|
||||
# - Service health monitoring
|
||||
# - Process management and monitoring
|
||||
# - Interactive menu system
|
||||
#
|
||||
# Related Scripts:
|
||||
# - backup-plex.sh: Comprehensive backup solution
|
||||
# - restore-plex.sh: Backup restoration utilities
|
||||
# - monitor-plex-backup.sh: Backup system monitoring
|
||||
# - validate-plex-backups.sh: Backup validation tools
|
||||
# - test-plex-backup.sh: Testing framework
|
||||
#
|
||||
# Usage:
|
||||
# ./plex.sh start # Start Plex service
|
||||
# ./plex.sh stop # Stop Plex service
|
||||
# ./plex.sh restart # Restart Plex service
|
||||
# ./plex.sh status # Show service status
|
||||
# ./plex.sh web # Open web interface
|
||||
# ./plex.sh # Interactive menu
|
||||
#
|
||||
# Dependencies:
|
||||
# - systemctl (systemd service management)
|
||||
# - Plex Media Server package
|
||||
# - Web browser (for web interface launching)
|
||||
#
|
||||
# Exit Codes:
|
||||
# 0 - Success
|
||||
# 1 - General error
|
||||
# 2 - Service operation failure
|
||||
# 3 - Invalid command or option
|
||||
#
|
||||
################################################################################
|
||||
|
||||
# 🎬 Plex Media Server Management Script
|
||||
# A sexy, modern script for managing Plex Media Server with style
|
||||
# Author: acedanger
|
||||
@@ -60,7 +105,7 @@ show_loading() {
|
||||
local pid="$2"
|
||||
local spin='-\|/'
|
||||
local i=0
|
||||
|
||||
|
||||
echo -ne "${CYAN}${HOURGLASS} ${message}${RESET}"
|
||||
while kill -0 "$pid" 2>/dev/null; do
|
||||
i=$(( (i+1) %4 ))
|
||||
@@ -73,20 +118,20 @@ show_loading() {
|
||||
# 🚀 Enhanced start function
|
||||
start_plex() {
|
||||
print_status "${ROCKET}" "Starting Plex Media Server..." "${GREEN}"
|
||||
|
||||
|
||||
if systemctl is-active --quiet "$PLEX_SERVICE"; then
|
||||
print_status "${INFO}" "Plex is already running!" "${YELLOW}"
|
||||
show_detailed_status
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
||||
sudo systemctl start "$PLEX_SERVICE" &
|
||||
local pid=$!
|
||||
show_loading "Initializing Plex Media Server" $pid
|
||||
wait $pid
|
||||
|
||||
|
||||
sleep 2 # Give it a moment to fully start
|
||||
|
||||
|
||||
if systemctl is-active --quiet "$PLEX_SERVICE"; then
|
||||
print_status "${CHECKMARK}" "Plex Media Server started successfully!" "${GREEN}"
|
||||
echo -e "${DIM}${CYAN}Access your server at: ${WHITE}${PLEX_WEB_URL}${RESET}"
|
||||
@@ -100,17 +145,17 @@ start_plex() {
|
||||
# 🛑 Enhanced stop function
|
||||
stop_plex() {
|
||||
print_status "${STOP_SIGN}" "Stopping Plex Media Server..." "${YELLOW}"
|
||||
|
||||
|
||||
if ! systemctl is-active --quiet "$PLEX_SERVICE"; then
|
||||
print_status "${INFO}" "Plex is already stopped!" "${YELLOW}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
||||
sudo systemctl stop "$PLEX_SERVICE" &
|
||||
local pid=$!
|
||||
show_loading "Gracefully shutting down Plex" $pid
|
||||
wait $pid
|
||||
|
||||
|
||||
if ! systemctl is-active --quiet "$PLEX_SERVICE"; then
|
||||
print_status "${CHECKMARK}" "Plex Media Server stopped successfully!" "${GREEN}"
|
||||
print_footer
|
||||
@@ -123,12 +168,12 @@ stop_plex() {
|
||||
# ♻️ Enhanced restart function
|
||||
restart_plex() {
|
||||
print_status "${RECYCLE}" "Restarting Plex Media Server..." "${BLUE}"
|
||||
|
||||
|
||||
if systemctl is-active --quiet "$PLEX_SERVICE"; then
|
||||
stop_plex
|
||||
echo ""
|
||||
fi
|
||||
|
||||
|
||||
start_plex
|
||||
}
|
||||
|
||||
@@ -136,19 +181,19 @@ restart_plex() {
|
||||
show_detailed_status() {
|
||||
local service_status
|
||||
service_status=$(systemctl is-active "$PLEX_SERVICE" 2>/dev/null || echo "inactive")
|
||||
|
||||
|
||||
echo -e "\n${BOLD}${BLUE}╔══════════════════════════════════════════════════════════════╗${RESET}"
|
||||
echo -e "${BOLD}${BLUE}║ SERVICE STATUS ║${RESET}"
|
||||
echo -e "${BOLD}${BLUE}╚══════════════════════════════════════════════════════════════╝${RESET}"
|
||||
|
||||
|
||||
case "$service_status" in
|
||||
"active")
|
||||
print_status "${CHECKMARK}" "Service Status: ${GREEN}${BOLD}ACTIVE${RESET}" "${GREEN}"
|
||||
|
||||
|
||||
# Get additional info
|
||||
local uptime
|
||||
uptime=$(systemctl show "$PLEX_SERVICE" --property=ActiveEnterTimestamp --value | xargs -I {} date -d {} "+%Y-%m-%d %H:%M:%S" 2>/dev/null || echo "Unknown")
|
||||
|
||||
|
||||
local memory_usage
|
||||
memory_usage=$(systemctl show "$PLEX_SERVICE" --property=MemoryCurrent --value 2>/dev/null || echo "0")
|
||||
if [[ "$memory_usage" != "0" ]] && [[ "$memory_usage" =~ ^[0-9]+$ ]]; then
|
||||
@@ -156,7 +201,7 @@ show_detailed_status() {
|
||||
else
|
||||
memory_usage="Unknown"
|
||||
fi
|
||||
|
||||
|
||||
echo -e "${DIM}${CYAN} Started: ${WHITE}${uptime}${RESET}"
|
||||
echo -e "${DIM}${CYAN} Memory Usage: ${WHITE}${memory_usage}${RESET}"
|
||||
echo -e "${DIM}${CYAN} Web Interface: ${WHITE}${PLEX_WEB_URL}${RESET}"
|
||||
@@ -174,7 +219,7 @@ show_detailed_status() {
|
||||
print_status "${INFO}" "Service Status: ${YELLOW}${BOLD}${service_status^^}${RESET}" "${YELLOW}"
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
# Show recent logs
|
||||
echo -e "\n${DIM}${CYAN}┌─── Recent Service Logs ───┐${RESET}"
|
||||
echo -e "${DIM}$(journalctl -u "$PLEX_SERVICE" --no-pager -n 3 --since "7 days ago" 2>/dev/null | tail -3 || echo "No recent logs available")${RESET}"
|
||||
@@ -206,19 +251,19 @@ main() {
|
||||
print_status "${CROSS}" "Don't run this script as root! Use your regular user account." "${RED}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Check if no arguments provided
|
||||
if [[ $# -eq 0 ]]; then
|
||||
print_header
|
||||
show_help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# Show header for all operations except help
|
||||
if [[ "${1,,}" != "help" ]] && [[ "${1,,}" != "--help" ]] && [[ "${1,,}" != "-h" ]]; then
|
||||
print_header
|
||||
fi
|
||||
|
||||
|
||||
case "${1,,}" in # Convert to lowercase
|
||||
"start")
|
||||
start_plex
|
||||
|
||||
Reference in New Issue
Block a user