@@ -49,7 +49,7 @@ def _get_service_pid(self, pid_file: Path) -> Optional[int]:
4949 except (OSError , ValueError , FileNotFoundError ):
5050 return None
5151
52- def _start_virtual_env_service (self , service_name : str , command : list , pid_file : Path , log_file : Path , working_dir : Path = None ):
52+ def _start_virtual_env_service (self , service_name : str , command : list , pid_file : Path , log_file : Path , working_dir : Path = None , env_vars : dict = None ):
5353 """Start a virtual environment service."""
5454 if self ._is_service_running (pid_file ):
5555 typer .echo (f"{ service_name } is already running (PID: { self ._get_service_pid (pid_file )} )" )
@@ -61,13 +61,19 @@ def _start_virtual_env_service(self, service_name: str, command: list, pid_file:
6161 # Use provided working directory or default to needle_home
6262 cwd = working_dir if working_dir else self .needle_home
6363
64+ # Prepare environment variables
65+ env = os .environ .copy ()
66+ if env_vars :
67+ env .update (env_vars )
68+
6469 # Start service in background
6570 with open (log_file , 'w' ) as log_f :
6671 process = subprocess .Popen (
6772 command ,
6873 stdout = log_f ,
6974 stderr = subprocess .STDOUT ,
70- cwd = cwd
75+ cwd = cwd ,
76+ env = env
7177 )
7278
7379 # Save PID
@@ -118,17 +124,17 @@ def start_services(self):
118124 time .sleep (15 )
119125
120126 # Start image generator hub
121- if (self .needle_home .parent / "ImageGeneratorsHub" ).exists ():
127+ image_gen_dir = self .needle_home / "ImageGeneratorsHub"
128+ if image_gen_dir .exists () and (image_gen_dir / ".venv" ).exists ():
122129 typer .echo ("Starting image-generator-hub..." )
123- image_gen_dir = self . needle_home . parent / "ImageGeneratorsHub "
130+ python_path = image_gen_dir / ".venv" / "bin" / "python "
124131 command = [
125- "bash" , "-c" ,
126- f"cd { image_gen_dir } && source .venv/bin/activate && uvicorn main:app --host 0.0.0.0 --port 8010"
132+ str (python_path ), "-m" , "uvicorn" , "main:app" , "--host" , "0.0.0.0" , "--port" , "8010"
127133 ]
128134 log_file = self .needle_home / "logs" / "image-generator-hub.log"
129- self ._start_virtual_env_service ("Image-generator-hub" , command , self .image_gen_pid_file , log_file )
135+ self ._start_virtual_env_service ("Image-generator-hub" , command , self .image_gen_pid_file , log_file , image_gen_dir )
130136 else :
131- typer .echo ("Warning: ImageGeneratorsHub not found. Image generation will not be available." )
137+ typer .echo ("Warning: ImageGeneratorsHub not found or virtual environment not set up . Image generation will not be available." )
132138
133139 # Start backend
134140 typer .echo ("Starting Needle backend..." )
@@ -138,7 +144,11 @@ def start_services(self):
138144 str (python_path ), "-m" , "uvicorn" , "main:app" , "--host" , "0.0.0.0" , "--port" , "8000" , "--reload"
139145 ]
140146 log_file = self .needle_home / "logs" / "backend.log"
141- self ._start_virtual_env_service ("Backend" , command , self .backend_pid_file , log_file , backend_dir )
147+ # Set the config directory path to the correct location
148+ env_vars = {
149+ "SERVICE__CONFIG_DIR_PATH" : str (self .needle_home / "configs" / "fast" )
150+ }
151+ self ._start_virtual_env_service ("Backend" , command , self .backend_pid_file , log_file , backend_dir , env_vars )
142152
143153 typer .echo ("All services started!" )
144154 typer .echo ("🌐 Access Points:" )
0 commit comments