feat: enhance protection for JuiceFS Redis service and update command arguments
This commit is contained in:
parent
80ec188190
commit
09093392cd
@ -11,8 +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"
|
||||
# Protected services that should never be stopped
|
||||
PROTECTED_SERVICES = ["juicefs-redis"]
|
||||
|
||||
|
||||
def get_service_path(service_name):
|
||||
@ -99,12 +99,13 @@ def cmd_stop(args):
|
||||
printfe("yellow", "No running services found to stop")
|
||||
return 0
|
||||
|
||||
# Filter out the protected service
|
||||
safe_services = [s for s in running_services if s != PROTECTED_SERVICE]
|
||||
# Filter out the protected services
|
||||
safe_services = [s for s in running_services if s not in PROTECTED_SERVICES]
|
||||
|
||||
# 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")
|
||||
# Check if protected services were filtered out
|
||||
protected_running = [s for s in running_services if s in PROTECTED_SERVICES]
|
||||
if protected_running:
|
||||
printfe("yellow", f"Note: {', '.join(protected_running)} will not be stopped as they are protected services")
|
||||
|
||||
if not safe_services:
|
||||
printfe("yellow", "No services to stop (all running services are protected)")
|
||||
@ -129,10 +130,10 @@ 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")
|
||||
# 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)
|
||||
|
||||
@ -285,7 +286,8 @@ def main():
|
||||
start_parser = subparsers.add_parser("start", help="Start a Docker service")
|
||||
start_group = start_parser.add_mutually_exclusive_group(required=True)
|
||||
start_group.add_argument("--all", action="store_true", help="Start all services")
|
||||
start_group.add_argument("--service", dest="service", help="Service to start")
|
||||
start_group.add_argument("service", nargs="?", help="Service to start")
|
||||
start_group.add_argument("--service", dest="service", help="Service to start (deprecated)")
|
||||
|
||||
# Stop command
|
||||
stop_parser = subparsers.add_parser("stop", help="Stop a Docker service")
|
||||
@ -293,7 +295,8 @@ def main():
|
||||
stop_group.add_argument(
|
||||
"--all", action="store_true", help="Stop all running services"
|
||||
)
|
||||
stop_group.add_argument("--service", dest="service", help="Service to stop")
|
||||
stop_group.add_argument("service", nargs="?", help="Service to stop")
|
||||
stop_group.add_argument("--service", dest="service", help="Service to stop (deprecated)")
|
||||
|
||||
# Restart command
|
||||
restart_parser = subparsers.add_parser("restart", help="Restart a Docker service")
|
||||
@ -308,7 +311,8 @@ def main():
|
||||
update_group.add_argument(
|
||||
"--all", action="store_true", help="Update all running services"
|
||||
)
|
||||
update_group.add_argument("--service", dest="service", help="Service to update")
|
||||
update_group.add_argument("service", nargs="?", help="Service to update")
|
||||
update_group.add_argument("--service", dest="service", help="Service to update (deprecated)")
|
||||
|
||||
# PS command
|
||||
ps_parser = subparsers.add_parser("ps", help="Show Docker service status")
|
||||
|
Loading…
x
Reference in New Issue
Block a user