Skip to content

Commit 48ebfc9

Browse files
authored
chg: update multi node command (#62)
1 parent 9338676 commit 48ebfc9

File tree

4 files changed

+60
-240
lines changed

4 files changed

+60
-240
lines changed

conf/private_net_layout.toml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# [database]
2-
# database_tar = "/path/to/database"
3-
41
# [[nodes]]
52
# node_ip = "192.168.1.1" # Remote node's IP
6-
# node_direcotry = "/path/to/direcotry" # Remote node's working direcotry for node
3+
# node_directory = "/path/to/direcotry" # Remote node's working direcotry for node
74
# config_file = "/path/to/config" # Config file for remote node
5+
# docker_compose_file =”/path/to/config“ # Config docker-compose file for remote node
86
# node_type = "fullnode/sr" # Fullnode or SR node
97
# ssh_port = 22
108
# ssh_user = "user1"
@@ -13,22 +11,21 @@
1311

1412
# [[nodes]]
1513
# node_ip = "192.168.1.2" # Changed IP to demonstrate different nodes
16-
# node_direcotry = "/path/to/direcotry"
14+
# node_directory = "/path/to/directory"
1715
# config_file = "/path/to/config"
16+
# docker_compose_file =”/path/to/config“ # Config docker-compose file for remote node
1817
# node_type = "fullnode/sr"
1918
# ssh_port = 2222 # Custom SCP port for this node
2019
# ssh_user = "user2"
2120
# # No password or key; assumes SSH agent or pre-configured key
2221

23-
[database]
24-
database_tar = "/Users/barbatos/Downloads/hello.tgz"
2522

2623
[[nodes]]
2724
node_ip = "ec2-3-25-116-244.ap-southeast-2.compute.amazonaws.com"
28-
node_direcotry = "/home/ubuntu/mytest"
29-
config_file = "/Users/barbatos/Documents/code/md/mydev/tron-docker/conf/private_net_config_others.conf"
30-
node_type = "fullnode"
25+
node_directory = "/home/ubuntu/mytest"
26+
config_file = "/Users/ubuntu/conf/private_net_config_others.conf"
27+
docker_compose_file = "/Users/ubuntu/docker-compose.yml"
3128
ssh_port = 22
3229
ssh_user = "ubuntu"
3330
# ssh_password = "password1"
34-
ssh_key = "/Users/barbatos/Downloads/test-ci.pem" # Optional; uncomment if using key auth
31+
ssh_key = "/Users/ubuntu/Downloads/test-ci.pem" # Optional; uncomment if using key auth

tools/trond/cmd/node/envMultiNodes.go

Lines changed: 27 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -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
5452
type 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("\nNodes:")
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

191158
func mkdirRemoteDirectory(cfg Config) error {
192159
fmt.Println("\nPerforming 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)

tools/trond/cmd/node/runMulti.go

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package node
22

33
import (
44
"fmt"
5-
65
"github.com/MakeNowJust/heredoc/v2"
76
"github.com/spf13/cobra"
87
"github.com/tronprotocol/tron-docker/utils"
8+
"path/filepath"
99
)
1010

1111
var runMultiCmd = &cobra.Command{
@@ -34,9 +34,9 @@ var runMultiCmd = &cobra.Command{
3434
for i, node := range cfg.Nodes {
3535
fmt.Printf(" Node %d:\n", i)
3636
fmt.Printf(" IP: %s\n", node.NodeIP)
37-
fmt.Printf(" Directory: %s\n", node.NodeDirecotry)
37+
fmt.Printf(" Directory: %s\n", node.NodeDirectory)
3838
fmt.Printf(" Config File: %s\n", node.ConfigFile)
39-
fmt.Printf(" Type: %s\n", node.NodeType)
39+
fmt.Printf(" Docker-Config File: %s\n", node.DockerComposeFile)
4040
fmt.Printf(" SSH Port: %d\n", node.SSHPort)
4141
fmt.Printf(" SSH User: %s\n", node.SSHUser)
4242

@@ -55,13 +55,7 @@ var runMultiCmd = &cobra.Command{
5555
fmt.Printf(" SCP IP(%s) Port (%d) Status: %s\n", node.NodeIP, node.SSHPort, "Open")
5656
}
5757

58-
dockerComposeFile := "./single_node/docker-compose.fullnode.private.yml"
59-
if node.NodeType == "full" {
60-
dockerComposeFile = "./single_node/docker-compose.fullnode.private.yml"
61-
} else if node.NodeType == "sr" {
62-
dockerComposeFile = "./single_node/docker-compose.witness.private.yml"
63-
}
64-
58+
dockerComposeFile := filepath.Join(node.NodeDirectory, filepath.Base(node.DockerComposeFile))
6559
if err := utils.RunRemoteCompose(node.NodeIP, node.SSHPort, node.SSHUser, node.SSHPassword, node.SSHKey, dockerComposeFile, false); err != nil {
6660
fmt.Printf(" SSH start remote node failed: %v\n", err)
6761
return
@@ -74,28 +68,17 @@ var runMultiCmd = &cobra.Command{
7468

7569
var runMultiStopCmd = &cobra.Command{
7670
Use: "stop",
77-
Short: "Stop single java-tron node for different networks.",
71+
Short: "Stop multi java-tron node for different networks.",
7872
Long: heredoc.Doc(`
7973
The following configuration files are required:
8074
8175
- Configuration file(by default, these exist in the current repository directory)
82-
main network: ./conf/main_net_config.conf
83-
nile network: ./conf/nile_net_config.conf
84-
private network: ./conf/private_net_config_*.conf
85-
- Docker compose file(by default, these exist in the current repository directory)
86-
main network: ./single_node/docker-compose.fullnode.main.yml
87-
nile network: ./single_node/docker-compose.fullnode.nile.yml
88-
private network: ./single_node/docker-compose.witness.private.yml
76+
./conf/private_net_layout.toml
77+
8978
`),
9079
Example: heredoc.Doc(`
91-
# Stop single java-tron fullnode for main network
92-
$ ./trond node run-single stop -t full-main
93-
94-
# Stop single java-tron fullnode for nile network
95-
$ ./trond node run-single stop -t full-nile
96-
97-
# Stop single java-tron witness node for private network
98-
$ ./trond node run-single stop -t witness-private
80+
# Stop multi java-tron node
81+
$ ./trond node run-multi stop
9982
`),
10083
Run: func(cmd *cobra.Command, args []string) {
10184

@@ -107,9 +90,8 @@ var runMultiStopCmd = &cobra.Command{
10790
for i, node := range cfg.Nodes {
10891
fmt.Printf(" Node %d:\n", i)
10992
fmt.Printf(" IP: %s\n", node.NodeIP)
110-
fmt.Printf(" Directory: %s\n", node.NodeDirecotry)
93+
fmt.Printf(" Directory: %s\n", node.NodeDirectory)
11194
fmt.Printf(" Config File: %s\n", node.ConfigFile)
112-
fmt.Printf(" Type: %s\n", node.NodeType)
11395
fmt.Printf(" SSH Port: %d\n", node.SSHPort)
11496
fmt.Printf(" SSH User: %s\n", node.SSHUser)
11597

@@ -128,13 +110,7 @@ var runMultiStopCmd = &cobra.Command{
128110
fmt.Printf(" SCP IP(%s) Port (%d) Status: %s\n", node.NodeIP, node.SSHPort, "Open")
129111
}
130112

131-
dockerComposeFile := "./single_node/docker-compose.fullnode.private.yml"
132-
if node.NodeType == "full" {
133-
dockerComposeFile = "./single_node/docker-compose.fullnode.private.yml"
134-
} else if node.NodeType == "sr" {
135-
dockerComposeFile = "./single_node/docker-compose.witness.private.yml"
136-
}
137-
113+
dockerComposeFile := filepath.Join(node.NodeDirectory, filepath.Base(node.DockerComposeFile))
138114
if err := utils.RunRemoteCompose(node.NodeIP, node.SSHPort, node.SSHUser, node.SSHPassword, node.SSHKey, dockerComposeFile, true); err != nil {
139115
fmt.Printf(" SSH stop remote node failed: %v\n", err)
140116
return

0 commit comments

Comments
 (0)