|
|
@ -12,8 +12,36 @@ import ( |
|
|
|
const ( |
|
|
|
const ( |
|
|
|
StandaloneScript = "deploy_standalone.sh" |
|
|
|
StandaloneScript = "deploy_standalone.sh" |
|
|
|
ClusterScript = "deploy_cluster.sh" |
|
|
|
ClusterScript = "deploy_cluster.sh" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RedisShake = "redis-shake" |
|
|
|
|
|
|
|
RedisShakeConf = "redis-shake.conf" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func run(cmd *exec.Cmd) error { |
|
|
|
|
|
|
|
if err := cmd.Start(); err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("start failed[%v]", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := cmd.Wait(); err != nil { |
|
|
|
|
|
|
|
if exiterr, ok := err.(*exec.ExitError); ok { |
|
|
|
|
|
|
|
// The program has exited with an exit code != 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This works on both Unix and Windows. Although package
|
|
|
|
|
|
|
|
// syscall is generally platform dependent, WaitStatus is
|
|
|
|
|
|
|
|
// defined for both Unix and Windows and in both cases has
|
|
|
|
|
|
|
|
// an ExitStatus() method with the same signature.
|
|
|
|
|
|
|
|
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok { |
|
|
|
|
|
|
|
if retCode := status.ExitStatus(); retCode != 0 { |
|
|
|
|
|
|
|
return fmt.Errorf("run with exit code[%v]", retCode) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return fmt.Errorf("wait failed[%s]", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
* tp: standalone, cluster |
|
|
|
* tp: standalone, cluster |
|
|
|
* port: redis-server port |
|
|
|
* port: redis-server port |
|
|
@ -41,27 +69,38 @@ func Deploy(tp string, port int, cmd string, node int) error { |
|
|
|
execCmd = exec.Command(path, portS, cmd, strconv.Itoa(node)) |
|
|
|
execCmd = exec.Command(path, portS, cmd, strconv.Itoa(node)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if err := execCmd.Start(); err != nil { |
|
|
|
return run(execCmd) |
|
|
|
return fmt.Errorf("start failed[%v]", err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := execCmd.Wait(); err != nil { |
|
|
|
// start redis-shake with given configuration, mode means sync/rump/dump/restore/decode
|
|
|
|
if exiterr, ok := err.(*exec.ExitError); ok { |
|
|
|
func StartShake(shakeDir, runDir string, conf map[string]interface{}, mode string) error { |
|
|
|
// The program has exited with an exit code != 0
|
|
|
|
if _, err := os.Stat(runDir); os.IsNotExist(err) { |
|
|
|
|
|
|
|
if err := os.Mkdir(runDir, os.ModePerm); err != nil { |
|
|
|
|
|
|
|
return fmt.Errorf("mkdir %v failed[%v]", runDir, err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// This works on both Unix and Windows. Although package
|
|
|
|
from := fmt.Sprintf("%s/%s", shakeDir, RedisShake) |
|
|
|
// syscall is generally platform dependent, WaitStatus is
|
|
|
|
to := fmt.Sprintf("%s/%s", runDir, RedisShake) |
|
|
|
// defined for both Unix and Windows and in both cases has
|
|
|
|
cpCmd := exec.Command("cp", from, to) |
|
|
|
// an ExitStatus() method with the same signature.
|
|
|
|
if err := run(cpCmd); err != nil { |
|
|
|
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok { |
|
|
|
return fmt.Errorf("copy file from [%v] to [%v] failed[%v]", from, to, err) |
|
|
|
if retCode := status.ExitStatus(); retCode != 0 { |
|
|
|
|
|
|
|
return fmt.Errorf("run with exit code[%v]", retCode) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
f, err := os.Create(RedisShakeConf) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
|
|
|
|
return fmt.Errorf("wait failed[%s]", err) |
|
|
|
// write conf
|
|
|
|
|
|
|
|
for key, val := range conf { |
|
|
|
|
|
|
|
_, err := f.WriteString(fmt.Sprintf("%v = %v\n", key, val)) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return nil |
|
|
|
// start redis-shake
|
|
|
|
|
|
|
|
execCmd := exec.Command(to, fmt.Sprintf("-type=%s", mode), fmt.Sprintf("-conf=%s", RedisShakeConf), "&") |
|
|
|
|
|
|
|
return run(execCmd) |
|
|
|
} |
|
|
|
} |