feat: add protection for JuiceFS Redis service to prevent accidental stopping

This commit is contained in:
Menno van Leeuwen 2025-03-14 17:29:42 +01:00
parent 3d5010e193
commit 484c421f22
Signed by: vleeuwenmenno
SSH Key Fingerprint: SHA256:OJFmjANpakwD3F2Rsws4GLtbdz1TJ5tkQF0RZmF0TRE

View File

@ -11,6 +11,8 @@ from helpers.functions import printfe, println, logo
# Base directory for Docker services $HOME/services # Base directory for Docker services $HOME/services
SERVICES_DIR = os.path.join(os.path.expanduser("~"), "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): def get_service_path(service_name):
@ -97,10 +99,21 @@ def cmd_stop(args):
printfe("yellow", "No running services found to stop") printfe("yellow", "No running services found to stop")
return 0 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 = [] failed_services = []
for service in running_services: for service in safe_services:
printfe("blue", f"\n=== Stopping {service} ===") printfe("blue", f"\n=== Stopping {service} ===")
result = run_docker_compose(["down"], service_name=service) result = run_docker_compose(["down"], service_name=service)
if result != 0: if result != 0:
@ -116,6 +129,11 @@ def cmd_stop(args):
printfe("green", "\nAll running services stopped successfully") printfe("green", "\nAll running services stopped successfully")
return 0 return 0
else: 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) return run_docker_compose(["down"], service_name=args.service)