Skip to content

Commit

Permalink
mysqlcluster: fix failed to start pod for first time radondb#545
Browse files Browse the repository at this point in the history
  • Loading branch information
acekingke committed Oct 24, 2022
1 parent 1c047d1 commit 52b4ddd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion mysqlcluster/container/auditlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion mysqlcluster/container/auditlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion mysqlcluster/container/slowlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion mysqlcluster/container/slowlog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 52b4ddd

Please sign in to comment.