feat: add protection for JuiceFS Redis service to prevent accidental stopping
This commit is contained in:
parent
3d5010e193
commit
484c421f22
@ -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)
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user