Skip to content

Commit

Permalink
cherry pick pingcap#3884 to release-1.1
Browse files Browse the repository at this point in the history
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
  • Loading branch information
handlerww authored and ti-srebot committed Apr 1, 2021
1 parent ef8b5a3 commit 48cd19c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/manager/member/template.go
Expand Up @@ -279,15 +279,27 @@ func RenderPumpStartScript(model *PumpStartScriptModel) (string, error) {
}

// tidbInitStartScriptTpl is the template string of tidb initializer start script
var tidbInitStartScriptTpl = template.Must(template.New("tidb-init-start-script").Parse(`import os, MySQLdb
var tidbInitStartScriptTpl = template.Must(template.New("tidb-init-start-script").Parse(`import os, sys, time, MySQLdb
host = '{{ .ClusterName }}-tidb'
permit_host = '{{ .PermitHost }}'
port = 4000
retry_count = 0
for i in range(0, 10):
try:
{{- if .TLS }}
conn = MySQLdb.connect(host=host, port=port, user='root', charset='utf8mb4',connect_timeout=5, ssl={'ca': '{{ .CAPath }}', 'cert': '{{ .CertPath }}', 'key': '{{ .KeyPath }}'})
conn = MySQLdb.connect(host=host, port=port, user='root', charset='utf8mb4',connect_timeout=5, ssl={'ca': '{{ .CAPath }}', 'cert': '{{ .CertPath }}', 'key': '{{ .KeyPath }}'})
{{- else }}
conn = MySQLdb.connect(host=host, port=port, user='root', connect_timeout=5, charset='utf8mb4')
conn = MySQLdb.connect(host=host, port=port, user='root', connect_timeout=5, charset='utf8mb4')
{{- end }}
except MySQLdb.OperationalError as e:
print(e)
retry_count += 1
time.sleep(1)
continue
break
if retry_count == 10:
sys.exit(1)
{{- if .PasswordSet }}
password_dir = '/etc/tidb/password'
for file in os.listdir(password_dir):
Expand Down

0 comments on commit 48cd19c

Please sign in to comment.