@@ -87,22 +87,22 @@ def __init__(self, clp_config: CLPConfig) -> None:
8787 self ._conf_dir = self ._clp_home / "etc"
8888
8989 @abstractmethod
90- def start (self ) -> None :
90+ def set_up_env (self ) -> None :
9191 """
92- Starts the components.
92+ Sets up all components to run by preparing environment variables, directories, and
93+ configuration files.
9394 """
9495
9596 @abstractmethod
96- def stop (self ) -> None :
97+ def start (self ) -> None :
9798 """
98- Stops the components.
99+ Starts the components.
99100 """
100101
101102 @abstractmethod
102- def _set_up_env (self ) -> None :
103+ def stop (self ) -> None :
103104 """
104- Sets up all components to run by preparing environment variables, directories, and
105- configuration files.
105+ Stops the components.
106106 """
107107
108108 def _set_up_env_for_database (self ) -> EnvVarsDict :
@@ -642,75 +642,7 @@ def __init__(self, clp_config: CLPConfig, instance_id: str) -> None:
642642 self ._project_name = f"clp-package-{ instance_id } "
643643 super ().__init__ (clp_config )
644644
645- def start (self ) -> None :
646- """
647- Starts CLP's components using Docker Compose.
648-
649- :raise: Propagates `check_docker_dependencies`'s exceptions.
650- :raise: Propagates `subprocess.run`'s exceptions.
651- """
652- check_docker_dependencies (
653- should_compose_project_be_running = False , project_name = self ._project_name
654- )
655- self ._set_up_env ()
656-
657- deployment_type = self ._clp_config .get_deployment_type ()
658- logger .info (f"Starting CLP using Docker Compose ({ deployment_type } deployment)..." )
659-
660- cmd = ["docker" , "compose" , "--project-name" , self ._project_name ]
661- if deployment_type == DeploymentType .BASE :
662- cmd += ["--file" , "docker-compose.base.yaml" ]
663- if self ._clp_config .mcp_server is not None :
664- cmd += ["--profile" , "mcp" ]
665- cmd += ["up" , "--detach" , "--wait" ]
666- subprocess .run (
667- cmd ,
668- cwd = self ._clp_home ,
669- check = True ,
670- )
671- logger .info ("Started CLP." )
672-
673- def stop (self ) -> None :
674- """
675- Stops CLP components deployed via Docker Compose.
676-
677- :raise: Propagates `subprocess.run`'s exceptions.
678- """
679- try :
680- check_docker_dependencies (
681- should_compose_project_be_running = True , project_name = self ._project_name
682- )
683- except DockerComposeProjectNotRunningError :
684- logger .info (
685- "Docker Compose project '%s' is not running. Nothing to stop." ,
686- self ._project_name ,
687- )
688- return
689- except DockerDependencyError as e :
690- logger .warning (
691- 'Docker dependencies check failed: "%s". Attempting to stop CLP containers '
692- "anyway..." ,
693- e ,
694- )
695- else :
696- logger .info ("Stopping all CLP containers using Docker Compose..." )
697-
698- subprocess .run (
699- ["docker" , "compose" , "--project-name" , self ._project_name , "down" ],
700- cwd = self ._clp_home ,
701- check = True ,
702- )
703- logger .info ("Stopped CLP." )
704-
705- @staticmethod
706- def _get_num_workers () -> int :
707- """
708- :return: Number of worker processes to run.
709- """
710- # This will change when we move from single to multi-container workers. See y-scope/clp#1424
711- return multiprocessing .cpu_count () // 2
712-
713- def _set_up_env (self ) -> None :
645+ def set_up_env (self ) -> None :
714646 # Generate container-specific config.
715647 container_clp_config = generate_docker_compose_container_config (self ._clp_config )
716648 num_workers = self ._get_num_workers ()
@@ -796,6 +728,73 @@ def _set_up_env(self) -> None:
796728 continue
797729 env_file .write (f"{ key } ={ value } \n " )
798730
731+ def start (self ) -> None :
732+ """
733+ Starts CLP's components using Docker Compose.
734+
735+ :raise: Propagates `check_docker_dependencies`'s exceptions.
736+ :raise: Propagates `subprocess.run`'s exceptions.
737+ """
738+ check_docker_dependencies (
739+ should_compose_project_be_running = False , project_name = self ._project_name
740+ )
741+
742+ deployment_type = self ._clp_config .get_deployment_type ()
743+ logger .info (f"Starting CLP using Docker Compose ({ deployment_type } deployment)..." )
744+
745+ cmd = ["docker" , "compose" , "--project-name" , self ._project_name ]
746+ if deployment_type == DeploymentType .BASE :
747+ cmd += ["--file" , "docker-compose.base.yaml" ]
748+ if self ._clp_config .mcp_server is not None :
749+ cmd += ["--profile" , "mcp" ]
750+ cmd += ["up" , "--detach" , "--wait" ]
751+ subprocess .run (
752+ cmd ,
753+ cwd = self ._clp_home ,
754+ check = True ,
755+ )
756+ logger .info ("Started CLP." )
757+
758+ def stop (self ) -> None :
759+ """
760+ Stops CLP components deployed via Docker Compose.
761+
762+ :raise: Propagates `subprocess.run`'s exceptions.
763+ """
764+ try :
765+ check_docker_dependencies (
766+ should_compose_project_be_running = True , project_name = self ._project_name
767+ )
768+ except DockerComposeProjectNotRunningError :
769+ logger .info (
770+ "Docker Compose project '%s' is not running. Nothing to stop." ,
771+ self ._project_name ,
772+ )
773+ return
774+ except DockerDependencyError as e :
775+ logger .warning (
776+ 'Docker dependencies check failed: "%s". Attempting to stop CLP containers '
777+ "anyway..." ,
778+ e ,
779+ )
780+ else :
781+ logger .info ("Stopping all CLP containers using Docker Compose..." )
782+
783+ subprocess .run (
784+ ["docker" , "compose" , "--project-name" , self ._project_name , "down" ],
785+ cwd = self ._clp_home ,
786+ check = True ,
787+ )
788+ logger .info ("Stopped CLP." )
789+
790+ @staticmethod
791+ def _get_num_workers () -> int :
792+ """
793+ :return: Number of worker processes to run.
794+ """
795+ # This will change when we move from single to multi-container workers. See y-scope/clp#1424
796+ return multiprocessing .cpu_count () // 2
797+
799798
800799def get_or_create_instance_id (clp_config : CLPConfig ) -> str :
801800 """
0 commit comments