@@ -14,7 +14,7 @@ var envMultiCmd = &cobra.Command{
1414 Use : "env-multi" ,
1515 Short : "Check and configure node environment across multiple nodes." ,
1616 Long : heredoc .Doc (`
17- Warning: this command only support configuration for remote nodes, not inlude the local node on the same server. For local node setup, please refer to "./trond node run-single"
17+ Warning: this command only support configuration for remote nodes, not include the local node on the same server. For local node setup, please refer to "./trond node run-single"
1818
1919 Default environment configuration for node operation:
2020
@@ -24,15 +24,13 @@ var envMultiCmd = &cobra.Command{
2424
2525 - Configuration file for private network layout (Please refer to the example configuration file and rewrite it according to your needs)
2626 ./conf/private_net_layout.toml
27-
28- - Docker compose file(by default, these exist in the current repository directory)
29- single node
30- private network witness: ./single_node/docker-compose.witness.private.yml
31- private network fullnode: ./single_node/docker-compose.fullnode.private.yml
3227 ` ),
3328 Example : heredoc .Doc (`
3429 # Check and configure node local environment
3530 $ ./trond node env-multi
31+
32+ # Use the scp command to copy files and synchronize databases between multiple nodes:
33+ $ scp -P 2222 local_file.txt [email protected] :/home/user/ 3634 ` ),
3735 Run : func (cmd * cobra.Command , args []string ) {
3836 if checkFalse , cfg := checkEnvForMulti (); checkFalse {
@@ -52,18 +50,15 @@ var envMultiCmd = &cobra.Command{
5250
5351// Config struct to match TOML
5452type Config struct {
55- Database struct {
56- DatabaseTar string `mapstructure:"database_tar"`
57- }
5853 Nodes []struct {
59- NodeIP string `mapstructure:"node_ip"`
60- NodeDirecotry string `mapstructure:"node_direcotry "`
61- ConfigFile string `mapstructure:"config_file"`
62- NodeType string `mapstructure:"node_type "`
63- SSHPort int `mapstructure:"ssh_port"`
64- SSHUser string `mapstructure:"ssh_user"`
65- SSHPassword string `mapstructure:"ssh_password"`
66- SSHKey string `mapstructure:"ssh_key"` // Optional private key path
54+ NodeIP string `mapstructure:"node_ip"`
55+ NodeDirectory string `mapstructure:"node_directory "`
56+ ConfigFile string `mapstructure:"config_file"`
57+ DockerComposeFile string `mapstructure:"docker_compose_file "`
58+ SSHPort int `mapstructure:"ssh_port"`
59+ SSHUser string `mapstructure:"ssh_user"`
60+ SSHPassword string `mapstructure:"ssh_password"`
61+ SSHKey string `mapstructure:"ssh_key"` // Optional private key path
6762 }
6863}
6964
@@ -93,24 +88,13 @@ func checkEnvForMulti() (bool, Config) {
9388 }
9489
9590 // Access config
96- fmt .Println ("Database Config:" )
97- fmt .Printf (" Path: %s\n " , cfg .Database .DatabaseTar )
98- if len (cfg .Database .DatabaseTar ) == 0 {
99- fmt .Println ("Database: not provide database, the chain will start from block 0" )
100- } else {
101- if yes , isDir := utils .PathExists (cfg .Database .DatabaseTar ); ! yes || isDir {
102- fmt .Println ("Error: file not exists or not a file:" , cfg .Database .DatabaseTar )
103- checkFalse = true
104- }
105- }
106-
10791 fmt .Println ("\n Nodes:" )
10892 for i , node := range cfg .Nodes {
10993 fmt .Printf (" Node %d:\n " , i )
11094 fmt .Printf (" IP: %s\n " , node .NodeIP )
111- fmt .Printf (" Directory: %s\n " , node .NodeDirecotry )
95+ fmt .Printf (" Directory: %s\n " , node .NodeDirectory )
11296 fmt .Printf (" Config File: %s\n " , node .ConfigFile )
113- fmt .Printf (" Type : %s\n " , node .NodeType )
97+ fmt .Printf (" Docker Compose File : %s\n " , node .DockerComposeFile )
11498 fmt .Printf (" SSH Port: %d\n " , node .SSHPort )
11599 fmt .Printf (" SSH User: %s\n " , node .SSHUser )
116100
@@ -130,7 +114,11 @@ func checkEnvForMulti() (bool, Config) {
130114 }
131115
132116 if yes , isDir := utils .PathExists (node .ConfigFile ); ! yes || isDir {
133- fmt .Println ("Error: file not exists or not a file:" , node .ConfigFile )
117+ fmt .Println ("Error: config file not exists or not a file:" , node .ConfigFile )
118+ checkFalse = true
119+ }
120+ if yes , isDir := utils .PathExists (node .DockerComposeFile ); ! yes || isDir {
121+ fmt .Println ("Error: docker-compose file not exists or not a file:" , node .ConfigFile )
134122 checkFalse = true
135123 }
136124 }
@@ -143,8 +131,8 @@ func attemptSCPTransfer(cfg Config) error {
143131
144132 for i , node := range cfg .Nodes {
145133 fmt .Printf (" Node %d (%s):\n " , i , node .NodeIP )
146- fmt .Printf (" Attempting to SCP transfer of %s to %s:%s as %s...\n " , node .ConfigFile , node .NodeIP , node .NodeDirecotry , node .SSHUser )
147- remotePath := filepath .Join (node .NodeDirecotry , "conf" , filepath .Base (node .ConfigFile ))
134+ fmt .Printf (" Attempting to SCP transfer of %s to %s:%s as %s...\n " , node .ConfigFile , node .NodeIP , node .NodeDirectory , node .SSHUser )
135+ remotePath := filepath .Join (node .NodeDirectory , "conf" , filepath .Base (node .ConfigFile ))
148136 err := utils .SCPFile (node .NodeIP , node .SSHPort , node .SSHUser , node .SSHPassword , node .SSHKey , node .ConfigFile , remotePath )
149137 if err != nil {
150138 fmt .Printf (" SCP transfer failed: %v\n " , err )
@@ -153,16 +141,9 @@ func attemptSCPTransfer(cfg Config) error {
153141 fmt .Printf (" SCP transfer succeeded to %s\n " , node .NodeIP )
154142 }
155143
156- dockerComposeFile := "./single_node/docker-compose.fullnode.private.yml"
157- if node .NodeType == "full" {
158- dockerComposeFile = "./single_node/docker-compose.fullnode.private.yml"
159- } else if node .NodeType == "sr" {
160- dockerComposeFile = "./single_node/docker-compose.witness.private.yml"
161- }
162-
163- fmt .Printf (" Attempting to SCP transfer of %s to %s:%s as %s...\n " , dockerComposeFile , node .NodeIP , node .NodeDirecotry , node .SSHUser )
164- remotePath = filepath .Join (node .NodeDirecotry , "single_node" , filepath .Base (dockerComposeFile ))
165- err = utils .SCPFile (node .NodeIP , node .SSHPort , node .SSHUser , node .SSHPassword , node .SSHKey , node .ConfigFile , remotePath )
144+ fmt .Printf (" Attempting to SCP transfer of %s to %s:%s as %s...\n " , node .DockerComposeFile , node .NodeIP , node .NodeDirectory , node .SSHUser )
145+ remotePath = filepath .Join (node .NodeDirectory , filepath .Base (node .DockerComposeFile ))
146+ err = utils .SCPFile (node .NodeIP , node .SSHPort , node .SSHUser , node .SSHPassword , node .SSHKey , node .DockerComposeFile , remotePath )
166147 if err != nil {
167148 fmt .Printf (" SCP transfer failed: %v\n " , err )
168149 return err
@@ -171,33 +152,19 @@ func attemptSCPTransfer(cfg Config) error {
171152 }
172153 }
173154
174- if len (cfg .Database .DatabaseTar ) != 0 {
175- for i , node := range cfg .Nodes {
176- fmt .Printf (" Node %d (%s):\n " , i , node .NodeIP )
177- fmt .Printf (" Attempting to SCP transfer of %s to %s:%s as %s...\n " , cfg .Database .DatabaseTar , node .NodeIP , node .NodeDirecotry , node .SSHUser )
178-
179- remotePath := filepath .Join (node .NodeDirecotry , filepath .Base (cfg .Database .DatabaseTar ))
180- err := utils .SCPFile (node .NodeIP , node .SSHPort , node .SSHUser , node .SSHPassword , node .SSHKey , cfg .Database .DatabaseTar , remotePath )
181- if err != nil {
182- fmt .Printf (" SCP transfer failed: %v\n " , err )
183- } else {
184- fmt .Printf (" SCP transfer succeeded to %s\n " , node .NodeIP )
185- }
186- }
187- }
188155 return nil
189156}
190157
191158func mkdirRemoteDirectory (cfg Config ) error {
192159 fmt .Println ("\n Performing SSH Mkdir:" )
193160
194- remoteDirs := []string {"logs" , "conf" , "output-directory" , "single_node" }
161+ remoteDirs := []string {"logs" , "conf" , "output-directory" }
195162
196163 for i , node := range cfg .Nodes {
197164 fmt .Printf (" Node %d (%s):\n " , i , node .NodeIP )
198165 for _ , item := range remoteDirs {
199- fmt .Printf (" Attempting to create directory %s to %s:%s as %s...\n " , item , node .NodeIP , node .NodeDirecotry , node .SSHUser )
200- remotePath := filepath .Join (node .NodeDirecotry , item )
166+ fmt .Printf (" Attempting to create directory %s to %s:%s as %s...\n " , item , node .NodeIP , node .NodeDirectory , node .SSHUser )
167+ remotePath := filepath .Join (node .NodeDirectory , item )
201168 err := utils .SSHMkdirIfNotExist (node .NodeIP , node .SSHPort , node .SSHUser , node .SSHPassword , node .SSHKey , remotePath )
202169 if err != nil {
203170 fmt .Printf (" Create directory failed: %v\n " , err )
0 commit comments