[ Agent ] [ App ] - fix mysql init bugs - 2
This commit is contained in:
@@ -5,7 +5,9 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -542,7 +544,8 @@ func (op *AgentOsOperator) loadMysqlInitScript(funcArgs []string) (bool, []strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Strings(jackeyLoveFileList)
|
// sort for numeric order
|
||||||
|
sortFileNames(jackeyLoveFileList)
|
||||||
log.InfoF("[loadMysqlInitScript] - all jackey love files are => %v", jackeyLoveFileList)
|
log.InfoF("[loadMysqlInitScript] - all jackey love files are => %v", jackeyLoveFileList)
|
||||||
|
|
||||||
// dispatch mysql execution command
|
// dispatch mysql execution command
|
||||||
@@ -553,7 +556,7 @@ func (op *AgentOsOperator) loadMysqlInitScript(funcArgs []string) (bool, []strin
|
|||||||
"[loadMysqlInitScript]- ip config error !",
|
"[loadMysqlInitScript]- ip config error !",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
load, result := MysqlSqlFileLoad(jackeyLoveFileList)
|
load, result := MysqlSqlFileLoad(jackeyLoveIP, jackeyLoveFileList)
|
||||||
if !load {
|
if !load {
|
||||||
return false, result
|
return false, result
|
||||||
}
|
}
|
||||||
@@ -563,6 +566,19 @@ func (op *AgentOsOperator) loadMysqlInitScript(funcArgs []string) (bool, []strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sortFileNames(fileNames []string) {
|
||||||
|
re := regexp.MustCompile(`(\d+)_`)
|
||||||
|
sort.Slice(fileNames, func(i, j int) bool {
|
||||||
|
numStr1 := re.FindStringSubmatch(fileNames[i])
|
||||||
|
numStr2 := re.FindStringSubmatch(fileNames[j])
|
||||||
|
|
||||||
|
num1, _ := strconv.Atoi(numStr1[1])
|
||||||
|
num2, _ := strconv.Atoi(numStr2[1])
|
||||||
|
|
||||||
|
return num1 < num2
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func (op *AgentOsOperator) checkMySQL(funcArgs []string) (bool, []string) {
|
func (op *AgentOsOperator) checkMySQL(funcArgs []string) (bool, []string) {
|
||||||
|
|
||||||
if !K8sCheckPodStatusTimeout("helm-mysql-0", funcArgs[0], 180) {
|
if !K8sCheckPodStatusTimeout("helm-mysql-0", funcArgs[0], 180) {
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MysqlSqlFileLoad(jackeyLoveFileList []string) (bool, []string) {
|
func MysqlSqlFileLoad(jackeyLoveIp string, jackeyLoveFileList []string) (bool, []string) {
|
||||||
|
|
||||||
dsn := "root:QzfXQhd3bQ@tcp(127.0.0.1:33306)"
|
dsn := "root:QzfXQhd3bQ@tcp(" + jackeyLoveIp + ":33306)"
|
||||||
db, err := sql.Open("mysql", dsn)
|
db, err := sql.Open("mysql", dsn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errConnect := fmt.Sprintf("[MysqlSqlFileLoad]- mysql connection error ! please check ! => %s ", dsn)
|
errConnect := fmt.Sprintf("[MysqlSqlFileLoad]- mysql connection error ! please check ! => %s ", dsn)
|
||||||
|
|||||||
Reference in New Issue
Block a user