@@ -9,6 +9,7 @@ use crate::commands::start::curio::constants::CURIO_LAYERS;
99use crate :: docker:: command_logger:: run_and_log_command_strings;
1010use crate :: docker:: network:: { lotus_network_name, pdp_miner_network_name} ;
1111use crate :: docker:: { container_exists, stop_and_remove_container} ;
12+ use crate :: docker:: init:: set_volume_ownership;
1213use crate :: paths:: {
1314 foc_devnet_bin, foc_devnet_curio_sp_volume, foc_devnet_genesis_sectors_pdp_sp,
1415 foc_devnet_proof_parameters, CONTAINER_FILECOIN_PROOF_PARAMS_PATH ,
@@ -46,7 +47,7 @@ pub fn start_curio_daemon(
4647 create_curio_directories ( context, sp_index) ?;
4748
4849 // Step 2: Create and start container
49- let docker_args = build_docker_run_args ( context, sp_index, & container_name) ?;
50+ let docker_args = build_docker_create_args ( context, sp_index, & container_name) ?;
5051 start_curio_container ( context, & container_name, docker_args) ?;
5152
5253 Ok ( ( ) )
@@ -63,31 +64,38 @@ fn create_curio_directories(context: &SetupContext, sp_index: usize) -> Result<(
6364 curio_sp_dir. join( "long-term-storage" ) ,
6465 ] ;
6566
66- for dir in dirs {
67- fs:: create_dir_all ( & dir) ?;
67+ for dir in & dirs {
68+ fs:: create_dir_all ( dir) ?;
6869 }
6970
71+ set_volume_ownership ( & curio_sp_dir) ?;
72+
7073 Ok ( ( ) )
7174}
7275
7376/// Create and start Curio container
77+ ///
78+ /// Uses docker create + network connect + start pattern so that:
79+ /// 1. Container is created but not started
80+ /// 2. Networks are connected while container is stopped
81+ /// 3. Container is started with Curio as PID 1 (logs work properly)
7482fn start_curio_container (
7583 context : & SetupContext ,
7684 container_name : & str ,
7785 mut docker_args : Vec < String > ,
7886) -> Result < ( ) , Box < dyn Error > > {
7987 info ! ( "Creating container {}..." , container_name) ;
8088
81- // Add image and command - run curio directly as the main process
89+ // Add image and command - Curio as main process
8290 docker_args. push ( crate :: constants:: CURIO_DOCKER_IMAGE . to_string ( ) ) ;
8391 docker_args. push ( "/usr/local/bin/lotus-bins/curio" . to_string ( ) ) ;
8492 docker_args. push ( "run" . to_string ( ) ) ;
8593 docker_args. push ( "--nosync" . to_string ( ) ) ;
8694 docker_args. push ( "--layers" . to_string ( ) ) ;
8795 docker_args. push ( CURIO_LAYERS . to_string ( ) ) ;
8896
89- // Execute docker run
90- let key = format ! ( "curio_daemon_start_ {}" , container_name) ;
97+ // Execute docker create (not run)
98+ let key = format ! ( "curio_daemon_create_ {}" , container_name) ;
9199 let output = run_and_log_command_strings ( "docker" , & docker_args, context, & key) ?;
92100
93101 if !output. status . success ( ) {
@@ -98,7 +106,7 @@ fn start_curio_container(
98106 . into ( ) ) ;
99107 }
100108
101- // Connect to filecoin network
109+ // Connect to filecoin network before starting
102110 let lotus_network = lotus_network_name ( context. run_id ( ) ) ;
103111 let network_args = vec ! [
104112 "network" . to_string( ) ,
@@ -109,13 +117,26 @@ fn start_curio_container(
109117 let key = format ! ( "curio_network_connect_{}" , container_name) ;
110118 let _ = run_and_log_command_strings ( "docker" , & network_args, context, & key) ; // Ignore errors if already connected
111119
112- info ! ( "Container created" ) ;
120+ // Start the container
121+ let start_args = vec ! [ "start" . to_string( ) , container_name. to_string( ) ] ;
122+ let key = format ! ( "curio_daemon_start_{}" , container_name) ;
123+ let output = run_and_log_command_strings ( "docker" , & start_args, context, & key) ?;
124+
125+ if !output. status . success ( ) {
126+ return Err ( format ! (
127+ "Failed to start curio container: {}" ,
128+ String :: from_utf8_lossy( & output. stderr)
129+ )
130+ . into ( ) ) ;
131+ }
132+
133+ info ! ( "Container created and started" ) ;
113134
114135 Ok ( ( ) )
115136}
116137
117- /// Build docker run arguments for Curio
118- fn build_docker_run_args (
138+ /// Build docker create arguments for Curio
139+ fn build_docker_create_args (
119140 context : & SetupContext ,
120141 sp_index : usize ,
121142 container_name : & str ,
@@ -127,8 +148,7 @@ fn build_docker_run_args(
127148 let genesis_sectors_dir = foc_devnet_genesis_sectors_pdp_sp ( run_id, sp_index) ;
128149
129150 let mut docker_args = vec ! [
130- "run" . to_string( ) ,
131- "-d" . to_string( ) ,
151+ "create" . to_string( ) ,
132152 "--name" . to_string( ) ,
133153 container_name. to_string( ) ,
134154 "--network" . to_string( ) ,
0 commit comments