add golang script

v4
vinllen 5 years ago
parent 6efda175d0
commit 62918746c1
  1. 2
      build.sh
  2. 67
      src/integration-test/deploy/deploy.go
  3. 5
      src/integration-test/main/main.go
  4. 2
      test/deploy_standalone.sh

@ -51,6 +51,8 @@ done
# copy scripts
cp scripts/start.sh ${output}/
cp scripts/stop.sh ${output}/
cp -r tools ${output}/
cp -r test ${output}/
if [ "Linux" == "$(uname -s)" ];then
# hypervisor

@ -0,0 +1,67 @@
package deploy
import (
"path/filepath"
"os"
"fmt"
"os/exec"
"syscall"
"strconv"
)
const (
StandaloneScript = "deploy_standalone.sh"
ClusterScript = "deploy_cluster.sh"
)
/*
* tp: standalone, cluster
* port: redis-server port
* cmd: start/stop
* node: node number, only used in cluster
*/
func Deploy(tp string, port int, cmd string, node int) error {
script := StandaloneScript
if tp == "cluster" {
script = ClusterScript
}
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
return fmt.Errorf("get path failed[%v]", err)
}
portS := fmt.Sprintf("%d", port)
path := fmt.Sprintf("%s/%s", dir, script)
var execCmd *exec.Cmd
if tp != "cluster" {
execCmd = exec.Command(path, portS, cmd)
} else {
execCmd = exec.Command(path, portS, cmd, strconv.Itoa(node))
}
if err := execCmd.Start(); err != nil {
return fmt.Errorf("start failed[%v]", err)
}
if err := execCmd.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
}

@ -0,0 +1,5 @@
package main
func main() {
}

@ -20,7 +20,7 @@ if [ $2 == "start" ]; then
# start
mkdir -p $subPath
cd $subPath
../../tools/redis-server --port $port --pidfile $subPath/$port.pid 1>/dev/null 2>&1 &
../tools/redis-server --port $port --pidfile $subPath/$port.pid 1>/dev/null 2>&1 &
else
# stop
kill -9 $(cat $subPath/$port.pid)

Loading…
Cancel
Save