Skip to content

Commit 49384da

Browse files
authored
Merge pull request #383 from acekingke/DebugMode
mysqlcluster: Debug Mode for Pod #375
2 parents 21d397a + 0e6a1d0 commit 49384da

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

docs/en-us/DebugMode.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Debug Mode
2+
When you want avoid the restart-on-fail loop for mysql container, You should use Debug Mode.
3+
it just use create a empty file `/var/lib/mysql/sleep-forever`
4+
for example:
5+
```bash
6+
kubectl exec -it sample-mysql-0 -c mysql -- sh -c 'touch /var/lib/mysql/sleep-forever'
7+
```
8+
it make pod sample-mysql-0's mysql container will never restart when mysqld is crashed.
9+
10+
# Remove Debug Mode
11+
12+
```bash
13+
kubectl exec -it sample-mysql-0 -c mysql -- sh -c 'rm /var/lib/mysql/sleep-forever'
14+
```
15+
restart the container

mysqlcluster/container/mysql.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ func (c *mysql) getImage() string {
4646

4747
// getCommand get the container command.
4848
func (c *mysql) getCommand() []string {
49-
return nil
49+
return []string{
50+
"sh",
51+
"-c",
52+
"while [ -f '/var/lib/mysql/sleep-forever' ] ;do sleep 2 ; done; /docker-entrypoint.sh mysqld",
53+
}
5054
}
5155

5256
// getEnvVars get the container env.
@@ -88,7 +92,15 @@ func (c *mysql) getLivenessProbe() *corev1.Probe {
8892
return &corev1.Probe{
8993
Handler: corev1.Handler{
9094
Exec: &corev1.ExecAction{
91-
Command: []string{"pgrep", "mysqld"},
95+
96+
/* /var/lib/mysql/sleep-forever is used to prevent mysql's container from exiting.
97+
kubectl exec -it sample-mysql-0 -c mysql -- sh -c 'touch /var/lib/mysql/sleep-forever'
98+
*/
99+
Command: []string{
100+
"sh",
101+
"-c",
102+
"if [ -f '/var/lib/mysql/sleep-forever' ] ;then exit 0 ; fi; pgrep mysqld",
103+
},
92104
},
93105
},
94106
InitialDelaySeconds: 30,
@@ -107,7 +119,7 @@ func (c *mysql) getReadinessProbe() *corev1.Probe {
107119
Command: []string{
108120
"sh",
109121
"-c",
110-
fmt.Sprintf(`test $(mysql --defaults-file=%s -NB -e "SELECT 1") -eq 1`, utils.ConfClientPath),
122+
fmt.Sprintf(`if [ -f '/var/lib/mysql/sleep-forever' ] ;then exit 0 ; fi; test $(mysql --defaults-file=%s -NB -e "SELECT 1") -eq 1`, utils.ConfClientPath),
111123
},
112124
},
113125
},

mysqlcluster/container/mysql_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ func TestGetMysqlImage(t *testing.T) {
5858
}
5959

6060
func TestGetMysqlCommand(t *testing.T) {
61-
assert.Nil(t, mysqlCase.Command)
61+
assert.Equal(t, mysqlCase.Command,
62+
[]string{"sh", "-c", "while [ -f '/var/lib/mysql/sleep-forever' ] ;do sleep 2 ; done; /docker-entrypoint.sh mysqld"})
6263
}
6364

6465
func TestGetMysqlEnvVar(t *testing.T) {
@@ -109,7 +110,7 @@ func TestGetMysqlLivenessProbe(t *testing.T) {
109110
livenessProbe := &corev1.Probe{
110111
Handler: corev1.Handler{
111112
Exec: &corev1.ExecAction{
112-
Command: []string{"pgrep", "mysqld"},
113+
Command: []string{"sh", "-c", "if [ -f '/var/lib/mysql/sleep-forever' ] ;then exit 0 ; fi; pgrep mysqld"},
113114
},
114115
},
115116
InitialDelaySeconds: 30,
@@ -125,7 +126,7 @@ func TestGetMysqlReadinessProbe(t *testing.T) {
125126
readinessProbe := &corev1.Probe{
126127
Handler: corev1.Handler{
127128
Exec: &corev1.ExecAction{
128-
Command: []string{"sh", "-c", `test $(mysql --defaults-file=/etc/mysql/client.conf -NB -e "SELECT 1") -eq 1`},
129+
Command: []string{"sh", "-c", `if [ -f '/var/lib/mysql/sleep-forever' ] ;then exit 0 ; fi; test $(mysql --defaults-file=/etc/mysql/client.conf -NB -e "SELECT 1") -eq 1`},
129130
},
130131
},
131132
InitialDelaySeconds: 10,

0 commit comments

Comments
 (0)