From 484c421f22b717452629b47c84f7d010ee25ae7d Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Fri, 14 Mar 2025 17:29:42 +0100 Subject: [PATCH] feat: add protection for JuiceFS Redis service to prevent accidental stopping --- bin/actions/service.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/bin/actions/service.py b/bin/actions/service.py index 1c47339..f748284 100755 --- a/bin/actions/service.py +++ b/bin/actions/service.py @@ -11,6 +11,8 @@ from helpers.functions import printfe, println, logo # Base directory for Docker services $HOME/services SERVICES_DIR = os.path.join(os.path.expanduser("~"), "services") +# Protected service that should never be stopped +PROTECTED_SERVICE = "juicefs-redis" def get_service_path(service_name): @@ -97,10 +99,21 @@ def cmd_stop(args): printfe("yellow", "No running services found to stop") return 0 - printfe("blue", f"Stopping all running services: {', '.join(running_services)}") + # Filter out the protected service + safe_services = [s for s in running_services if s != PROTECTED_SERVICE] + + # Check if the protected service was filtered out + if PROTECTED_SERVICE in running_services and PROTECTED_SERVICE not in safe_services: + printfe("yellow", f"Note: {PROTECTED_SERVICE} will not be stopped as it is a protected service") + + if not safe_services: + printfe("yellow", "No services to stop (all running services are protected)") + return 0 + + printfe("blue", f"Stopping all running services: {', '.join(safe_services)}") failed_services = [] - for service in running_services: + for service in safe_services: printfe("blue", f"\n=== Stopping {service} ===") result = run_docker_compose(["down"], service_name=service) if result != 0: @@ -116,6 +129,11 @@ def cmd_stop(args): printfe("green", "\nAll running services stopped successfully") return 0 else: + # Check if trying to stop the protected service + if args.service == PROTECTED_SERVICE: + printfe("red", f"Error: {PROTECTED_SERVICE} is a protected service and cannot be stopped") + printfe("yellow", f"The {PROTECTED_SERVICE} service is required for other services to work properly") + return 1 return run_docker_compose(["down"], service_name=args.service)