diff --git a/src/mysqld/args_handler.go b/src/mysqld/args_handler.go index a20aada..c274399 100644 --- a/src/mysqld/args_handler.go +++ b/src/mysqld/args_handler.go @@ -10,15 +10,15 @@ package mysqld // ArgsHandler for mysqld operation. type ArgsHandler interface { - // mysqld start args - Start() []string + // generate mysqld start args + GenerateStartCmd() []string - // mysqld stop args - Stop() []string + // generate mysqld stop args + GenerateStopCmd() []string - // mysqld isrunning args - IsRunning() []string + // generate mysqld isrunning args + GenerateIsRunningCmd() []string - // mysqld kill args - Kill() []string + // generate mysqld kill args + GenerateKillCmd() []string } diff --git a/src/mysqld/linux_args.go b/src/mysqld/linux_args.go index 7ac9021..076aba9 100644 --- a/src/mysqld/linux_args.go +++ b/src/mysqld/linux_args.go @@ -38,7 +38,7 @@ func NewLinuxArgs(conf *config.BackupConfig) *LinuxArgs { } // Start used to start mysqld. -func (l *LinuxArgs) Start() []string { +func (l *LinuxArgs) GenerateStartCmd() []string { safe57 := filepath.Join(l.conf.Basedir, mysqldsafe) args := []string{ "-c", @@ -48,7 +48,7 @@ func (l *LinuxArgs) Start() []string { } // Stop used to stop the mysqld. -func (l *LinuxArgs) Stop() []string { +func (l *LinuxArgs) GenerateStopCmd() []string { admin57 := filepath.Join(l.conf.Basedir, mysqladmin) args := []string{ "-c", @@ -62,7 +62,7 @@ func (l *LinuxArgs) Stop() []string { } // IsRunning used to check the mysqld is running or not. -func (l *LinuxArgs) IsRunning() []string { +func (l *LinuxArgs) GenerateIsRunningCmd() []string { // [m] is a trick to stop you picking up the actual grep process itself safe57 := fmt.Sprintf("[m]ysqld_safe --defaults-file=%s", l.conf.DefaultsFile) args := []string{ @@ -73,7 +73,7 @@ func (l *LinuxArgs) IsRunning() []string { } // Kill used to kill -9 the mysqld process. -func (l *LinuxArgs) Kill() []string { +func (l *LinuxArgs) GenerateKillCmd() []string { args := []string{ "-c", } diff --git a/src/mysqld/linux_args_test.go b/src/mysqld/linux_args_test.go index f23c268..6132d38 100644 --- a/src/mysqld/linux_args_test.go +++ b/src/mysqld/linux_args_test.go @@ -20,7 +20,7 @@ func TestLinuxStartArgs(t *testing.T) { conf := config.DefaultBackupConfig() linuxargs := NewLinuxArgs(conf) want := `-c /u01/mysql_20160606/bin/mysqld_safe --defaults-file=/etc/my3306.cnf > /dev/null&` - got := strings.Join(linuxargs.Start(), " ") + got := strings.Join(linuxargs.GenerateStartCmd(), " ") assert.Equal(t, want, got) } @@ -31,7 +31,7 @@ func TestLinuxStopArgs(t *testing.T) { // 1. passwords is null { want := `-c /u01/mysql_20160606/bin/mysqladmin -hlocalhost -uroot -P3306 shutdown` - got := strings.Join(linuxargs.Stop(), " ") + got := strings.Join(linuxargs.GenerateStopCmd(), " ") assert.Equal(t, want, got) } @@ -39,7 +39,7 @@ func TestLinuxStopArgs(t *testing.T) { { conf.Passwd = `ddd"` want := `-c /u01/mysql_20160606/bin/mysqladmin -hlocalhost -uroot -pddd" -P3306 shutdown` - got := strings.Join(linuxargs.Stop(), " ") + got := strings.Join(linuxargs.GenerateStopCmd(), " ") assert.Equal(t, want, got) } } @@ -47,13 +47,13 @@ func TestLinuxStopArgs(t *testing.T) { func TestLinuxIsRunningArgs(t *testing.T) { linuxargs := NewLinuxArgs(config.DefaultBackupConfig()) want := `-c ps aux | grep '[m]ysqld_safe --defaults-file=/etc/my3306.cnf' | wc -l` - got := strings.Join(linuxargs.IsRunning(), " ") + got := strings.Join(linuxargs.GenerateIsRunningCmd(), " ") assert.Equal(t, want, got) } func TestLinuxKillArgs(t *testing.T) { linuxargs := NewLinuxArgs(config.DefaultBackupConfig()) want := `-c kill -9 $(ps aux | grep '[-]-defaults-file=/etc/my3306.cnf' | awk '{print $2}')` - got := strings.Join(linuxargs.Kill(), " ") + got := strings.Join(linuxargs.GenerateKillCmd(), " ") assert.Equal(t, want, got) } diff --git a/src/mysqld/mock.go b/src/mysqld/mock.go index 9bcc9c0..546d809 100644 --- a/src/mysqld/mock.go +++ b/src/mysqld/mock.go @@ -76,7 +76,7 @@ func NewMockArgs() *MockArgs { } // Start used to start the mock. -func (l *MockArgs) Start() []string { +func (l *MockArgs) GenerateStartCmd() []string { args := []string{ "-c", "ls -l", @@ -86,7 +86,7 @@ func (l *MockArgs) Start() []string { } // Stop used to stop the mock. -func (l *MockArgs) Stop() []string { +func (l *MockArgs) GenerateStopCmd() []string { args := []string{ "-c", "ls -l", @@ -96,7 +96,7 @@ func (l *MockArgs) Stop() []string { } // IsRunning used to check the mock running. -func (l *MockArgs) IsRunning() []string { +func (l *MockArgs) GenerateIsRunningCmd() []string { args := []string{ "-c", "ls -l", @@ -106,7 +106,7 @@ func (l *MockArgs) IsRunning() []string { } // Kill used to kill the mock. -func (l *MockArgs) Kill() []string { +func (l *MockArgs) GenerateKillCmd() []string { args := []string{ "-c", "ls -l", diff --git a/src/mysqld/mysqld.go b/src/mysqld/mysqld.go index 95c0798..7112378 100644 --- a/src/mysqld/mysqld.go +++ b/src/mysqld/mysqld.go @@ -61,7 +61,7 @@ func (m *Mysqld) StartMysqld() error { } timeout := 3000 - args := m.argsHandler.Start() + args := m.argsHandler.GenerateStartCmd() if _, err := m.cmd.RunCommandWithTimeout(timeout, bash, args); err != nil { log.Error("mysqld.start..error[%+v]", err) return err @@ -81,7 +81,7 @@ func (m *Mysqld) StopMysqld() error { } timeout := 5000 - args := m.argsHandler.Stop() + args := m.argsHandler.GenerateStopCmd() if _, err := m.cmd.RunCommandWithTimeout(timeout, bash, args); err != nil { log.Error("mysqld.stop.mysqld.error[%+v]", err) return err @@ -98,7 +98,7 @@ func (m *Mysqld) KillMysqld() error { timeout := 3000 log := m.log - args := m.argsHandler.Kill() + args := m.argsHandler.GenerateKillCmd() log.Warning("mysqld.prepare.to.kill[%v]...", args) if _, err := m.cmd.RunCommandWithTimeout(timeout, bash, args); err != nil { log.Error("mysqld.kill.mysqld.error[%+v]", err) @@ -114,7 +114,7 @@ func (m *Mysqld) KillMysqld() error { func (m *Mysqld) isMysqldRunning() bool { log := m.log - args := m.argsHandler.IsRunning() + args := m.argsHandler.GenerateIsRunningCmd() outs, err := m.cmd.RunCommand(bash, args) if err != nil { log.Error("mysqld57.isMysqldRunning.error[%v:%+v]", outs, err)