88 "os"
99 "path/filepath"
1010 "regexp"
11+ "strconv"
1112 "strings"
1213 "telego/util"
1314 clusterconf "telego/util/cluster_conf"
@@ -291,14 +292,22 @@ func (m ModJobSshStruct) genOrGetKey() {
291292 fmt .Println ("User canceled config ssh no pw access" )
292293 os .Exit (1 )
293294 }
295+
296+ mainNodePort , err := strconv .Atoi (util .MainNodeSshPort )
297+ if err != nil {
298+ fmt .Println (color .RedString ("failed to convert main node ssh port to int: %v" , err ))
299+ os .Exit (1 )
300+ }
301+
294302 m .setupClusterInner (clusterconf.ClusterConfYmlModel {
295303 Global : clusterconf.ClusterConfYmlModelGlobal {
296304 SshUser : util .MainNodeUser ,
297305 SshPasswd : password ,
298306 },
299307 Nodes : map [string ]clusterconf.ClusterConfYmlModelNode {
300308 "dummy" : {
301- Ip : util .MainNodeIp ,
309+ Ip : util .MainNodeIp ,
310+ Port : mainNodePort ,
302311 },
303312 },
304313 })
@@ -310,6 +319,9 @@ func (m ModJobSshStruct) setupClusterInner(clusterConf clusterconf.ClusterConfYm
310319 fmt .Printf ("集群配置: %+v\n " , clusterConf )
311320
312321 hosts := funk .Map (clusterConf .Nodes , func (_ string , node clusterconf.ClusterConfYmlModelNode ) string {
322+ if node .Port != 0 {
323+ return fmt .Sprintf ("%s@%s:%d" , clusterConf .Global .SshUser , node .Ip , node .Port )
324+ }
313325 return fmt .Sprintf ("%s@%s" , clusterConf .Global .SshUser , node .Ip )
314326 }).([]string )
315327
@@ -322,30 +334,31 @@ func (m ModJobSshStruct) setupClusterInner(clusterConf clusterconf.ClusterConfYm
322334 }
323335 _ = base64 .StdEncoding .EncodeToString (pubkeybytes )
324336
325- output , logfps := util .StartRemoteCmds (
337+ // output, logfps :=
338+ util .StartRemoteCmds (
326339 hosts ,
327- // install telego,
328- util .ModRunCmd .CmdModels ().InstallTelegoWithPy ()+ "; " +
340+
341+ util .ModRunCmd .CmdModels ().InstallTelegoWithPy ()+ " && " +
329342 // update authorized_keys
330343 strings .Join (m .NewSshCmd (SshJob {Mode : SshModeSetupThisNode }.ModeString ()), " " ),
331344 clusterConf .Global .SshPasswd ,
332345 )
333- logfdebug , err := os .ReadFile (logfps [0 ] + ".debug" )
334- if err != nil {
335- fmt .Println (color .RedString ("read logfdebug failed: %v" , err ))
336- os .Exit (1 )
337- }
338- srcs := []string {output [0 ], string (logfdebug )}
339- keywords := []string {"error" , "失败" }
340- if funk .Any (srcs , func (src string ) bool {
341- return funk .Any (keywords , func (keyword string ) bool {
342- return strings .Contains (src , keyword )
343- })
344- }) {
345- fmt .Println (color .RedString ("ssh error: %s" , output ))
346- // debug sshd_config
347- util .ModRunCmd .NewBuilder ("cat" , "/etc/ssh/sshd_config" ).WithRoot ().ShowProgress ().BlockRun ()
348- }
346+ // logfdebug, err := os.ReadFile(logfps[0] + ".debug")
347+ // if err != nil {
348+ // fmt.Println(color.RedString("read logfdebug failed: %v", err))
349+ // os.Exit(1)
350+ // }
351+ // srcs := []string{output[0], string(logfdebug)}
352+ // keywords := []string{"error", "失败"}
353+ // if funk.Any(srcs, func(src string) bool {
354+ // return funk.Any(keywords, func(keyword string) bool {
355+ // return strings.Contains(src, keyword)
356+ // })
357+ // }) {
358+ // fmt.Println(color.RedString("ssh error: %s", output))
359+ // // debug sshd_config
360+ // util.ModRunCmd.NewBuilder("cat", "/etc/ssh/sshd_config").WithRoot().ShowProgress().BlockRun()
361+ // }
349362}
350363
351364// https://qcnoe3hd7k5c.feishu.cn/wiki/V6eHwZm1aiofeykaSd5cmgPcnSe#share-Hc1hdGT26oI4I0xPaplcEhMundd
0 commit comments