From 52b4dddd4914bca4b376a5bdf85dbb3044e60f0a Mon Sep 17 00:00:00 2001 From: acekingke Date: Mon, 17 Oct 2022 17:12:36 +0800 Subject: [PATCH] mysqlcluster: fix failed to start pod for first time #545 --- mysqlcluster/container/auditlog.go | 4 +++- mysqlcluster/container/auditlog_test.go | 2 +- mysqlcluster/container/slowlog.go | 4 +++- mysqlcluster/container/slowlog_test.go | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mysqlcluster/container/auditlog.go b/mysqlcluster/container/auditlog.go index f14b0eb1..05a0d313 100644 --- a/mysqlcluster/container/auditlog.go +++ b/mysqlcluster/container/auditlog.go @@ -43,7 +43,9 @@ func (c *auditLog) getImage() string { // getCommand get the container command. func (c *auditLog) getCommand() []string { - return []string{"tail", "-f", utils.LogsVolumeMountPath + "/mysql-audit.log"} + logsName := "/mysql-audit.log" + return []string{"sh", "-c", "for i in {120..0}; do if [ -f " + utils.LogsVolumeMountPath + logsName + " ] ; then break; fi;sleep 1; done; " + + "tail -f " + utils.LogsVolumeMountPath + logsName} } // getEnvVars get the container env. diff --git a/mysqlcluster/container/auditlog_test.go b/mysqlcluster/container/auditlog_test.go index 18d3e00b..264e97ab 100644 --- a/mysqlcluster/container/auditlog_test.go +++ b/mysqlcluster/container/auditlog_test.go @@ -43,7 +43,7 @@ var ( MysqlCluster: &auditlogMysqlCluster, } auditLogCase = EnsureContainer("auditlog", &testAuditlogCluster) - auditlogCommand = []string{"tail", "-f", "/var/log/mysql" + "/mysql-audit.log"} + auditlogCommand = []string{"sh", "-c", "for i in {120..0}; do if [ -f /var/log/mysql/mysql-audit.log ] ; then break; fi;sleep 1; done; tail -f /var/log/mysql/mysql-audit.log"} auditlogVolumeMounts = []corev1.VolumeMount{ { Name: "logs", diff --git a/mysqlcluster/container/slowlog.go b/mysqlcluster/container/slowlog.go index 7866eda5..3cf25944 100644 --- a/mysqlcluster/container/slowlog.go +++ b/mysqlcluster/container/slowlog.go @@ -43,7 +43,9 @@ func (c *slowLog) getImage() string { // getCommand get the container command. func (c *slowLog) getCommand() []string { - return []string{"tail", "-f", utils.LogsVolumeMountPath + "/mysql-slow.log"} + logsName := "/mysql-slow.log" + return []string{"sh", "-c", "for i in {120..0}; do if [ -f " + utils.LogsVolumeMountPath + logsName + " ] ; then break; fi;sleep 1; done; " + + "tail -f " + utils.LogsVolumeMountPath + logsName} } // getEnvVars get the container env. diff --git a/mysqlcluster/container/slowlog_test.go b/mysqlcluster/container/slowlog_test.go index bd2f9f70..686f4b06 100644 --- a/mysqlcluster/container/slowlog_test.go +++ b/mysqlcluster/container/slowlog_test.go @@ -54,7 +54,7 @@ func TestGetSlowlogImage(t *testing.T) { } func TestGetSlowlogCommand(t *testing.T) { - command := []string{"tail", "-f", "/var/log/mysql" + "/mysql-slow.log"} + command := []string{"sh", "-c", "for i in {120..0}; do if [ -f /var/log/mysql/mysql-slow.log ] ; then break; fi;sleep 1; done; tail -f /var/log/mysql/mysql-slow.log"} assert.Equal(t, command, slowlogCase.Command) }