File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 6
6
"log"
7
7
8
8
"github.com/go-sql-driver/mysql"
9
+ "github.com/spf13/cobra"
9
10
"github.com/tanji/mariadb-tools/dbhelper"
10
11
)
11
12
@@ -14,6 +15,10 @@ type topologyError struct {
14
15
Msg string
15
16
}
16
17
18
+ func init () {
19
+ rootCmd .AddCommand (topologyCmd )
20
+ }
21
+
17
22
func (e topologyError ) Error () string {
18
23
return fmt .Sprintf ("%v [#%v]" , e .Msg , e .Code )
19
24
}
@@ -148,3 +153,25 @@ func printTopology() {
148
153
logprintf ("DEBUG: Server [%d] %s %s" , k , v .URL , v .State )
149
154
}
150
155
}
156
+
157
+ var topologyCmd = & cobra.Command {
158
+ Use : "topology" ,
159
+ Short : "Print replication topology" ,
160
+ Long : `Print the replication topology by detecting master and slaves` ,
161
+ Run : func (cmd * cobra.Command , args []string ) {
162
+ repmgrFlagCheck ()
163
+ err := topologyInit ()
164
+ if err != nil {
165
+ log .Fatalln (err )
166
+ }
167
+ for _ , v := range servers {
168
+ fmt .Println (v .URL , v .State )
169
+ }
170
+ },
171
+ PostRun : func (cmd * cobra.Command , args []string ) {
172
+ // Close connections on exit.
173
+ for _ , server := range servers {
174
+ defer server .Conn .Close ()
175
+ }
176
+ },
177
+ }
You can’t perform that action at this time.
0 commit comments