This commit is contained in:
2025-09-23 14:06:26 +00:00
parent 8971d087a3
commit cfb80bd819
6 changed files with 61 additions and 44 deletions

View File

@@ -9,7 +9,7 @@ import argparse
# Import helper functions
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from helpers.functions import printfe, println, logo
from helpers.functions import printfe, println
# Base directory for Docker services $HOME/services
SERVICES_DIR = os.path.join(os.path.expanduser("~"), ".services")
@@ -109,7 +109,8 @@ def cmd_stop(args):
if protected_running:
printfe(
"yellow",
f"Note: {', '.join(protected_running)} will not be stopped as they are protected services",
f"Note: {', '.join(protected_running)} will not be stopped "
"as they are protected services",
)
if not safe_services:
@@ -136,19 +137,18 @@ def cmd_stop(args):
else:
printfe("green", "\nAll running services stopped successfully")
return 0
else:
# Check if trying to stop a protected service
if args.service in PROTECTED_SERVICES:
printfe(
"red",
f"Error: {args.service} is a protected service and cannot be stopped",
)
printfe(
"yellow",
f"The {args.service} service is required for other services to work properly",
)
return 1
return run_docker_compose(["down"], service_name=args.service)
# Check if trying to stop a protected service
if args.service in PROTECTED_SERVICES:
printfe(
"red",
f"Error: {args.service} is a protected service and cannot be stopped",
)
printfe(
"yellow",
f"The {args.service} service is required for other services to work properly",
)
return 1
return run_docker_compose(["down"], service_name=args.service)
def cmd_restart(args):
@@ -208,15 +208,15 @@ def cmd_update(args):
else:
printfe("green", "\nAll running services updated successfully")
return 0
else:
# The original single-service update logic
# First pull the latest images
pull_result = run_docker_compose(["pull"], service_name=args.service)
if pull_result != 0:
return pull_result
# Then bring the service up with the latest images
return run_docker_compose(["up", "-d"], service_name=args.service)
# The original single-service update logic
# First pull the latest images
pull_result = run_docker_compose(["pull"], service_name=args.service)
if pull_result != 0:
return pull_result
# Then bring the service up with the latest images
return run_docker_compose(["up", "-d"], service_name=args.service)
def cmd_ps(args):
@@ -262,18 +262,27 @@ def get_systemd_timer_status(timer_name):
"""Check if a systemd timer is active and enabled, and get next run time"""
# Check if timer is active (running/waiting)
active_result = subprocess.run(
["sudo", "systemctl", "is-active", timer_name], capture_output=True, text=True, check=False
["sudo", "systemctl", "is-active", timer_name],
capture_output=True,
text=True,
check=False,
)
# Check if timer is enabled (will start on boot)
enabled_result = subprocess.run(
["sudo", "systemctl", "is-enabled", timer_name], capture_output=True, text=True, check=False
["sudo", "systemctl", "is-enabled", timer_name],
capture_output=True,
text=True,
check=False,
)
# Check corresponding service status
service_name = timer_name.replace(".timer", ".service")
service_result = subprocess.run(
["sudo", "systemctl", "is-active", service_name], capture_output=True, text=True, check=False
["sudo", "systemctl", "is-active", service_name],
capture_output=True,
text=True,
check=False,
)
# Get next run time
@@ -297,7 +306,7 @@ def get_systemd_timer_status(timer_name):
return is_active, is_enabled, next_run, service_status
def cmd_list(args):
def cmd_list(args): # pylint: disable=unused-argument
"""List available Docker services and systemd services"""
# Docker services section
if not os.path.exists(SERVICES_DIR):
@@ -320,7 +329,10 @@ def cmd_list(args):
is_running = container_count > 0
if is_running:
status = f"[RUNNING - {container_count} container{'s' if container_count > 1 else ''}]"
status = (
f"[RUNNING - {container_count} container"
f"{'s' if container_count > 1 else ''}]"
)
color = "green"
else:
status = "[STOPPED]"
@@ -360,6 +372,7 @@ def cmd_list(args):
def main():
"""Main entry point for managing Docker services."""
parser = argparse.ArgumentParser(description="Manage Docker services")
subparsers = parser.add_subparsers(dest="command", help="Command to run")