コード例 #1
0
ファイル: main.go プロジェクト: johnvilsack/golang-stuff
func main() {
	flag.Parse()

	// Read target hosts from standard input
	var hosts []string
	buf := bufio.NewReader(os.Stdin)
	for {
		line, err := buf.ReadString('\n')
		if line != "" {
			line = strings.TrimSpace(line)
			hosts = append(hosts, line)
		}
		if err == io.EOF {
			break
		}
		if err != nil {
			fmt.Fprintf(os.Stderr, "Problem reading target hosts (%s)", err)
			os.Exit(1)
		}
	}

	// Log into each host and kill pertinent workers, using POSIX kill
	for _, h := range hosts {
		println("Clearing dead worker jails on", h)
		clearSh := fmt.Sprintf("%s %s\n", config.Config.Deploy.ClearHelperPath(), config.Config.Deploy.JailDir())
		_, stderr, err := posix.Exec("ssh", "", clearSh, h, "sh")
		if err != nil {
			fmt.Fprintf(os.Stderr, "Problem while clearing jails on %s (%s)\n", h, err)
			fmt.Fprintf(os.Stderr, "Remote clear-helper error output:\n%s\n", stderr)
		}
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: johnvilsack/golang-stuff
func main() {
	flag.Parse()

	// Parse WorkerID argument
	var (
		err    error
		id     circuit.WorkerID
		withID bool
	)
	if flag.NArg() == 1 {
		id, err = circuit.ParseWorkerID(flag.Arg(0))
		if err != nil {
			fmt.Fprintf(os.Stderr, "Problem parsing runtime ID (%s)\n", err)
			os.Exit(1)
		}
		withID = true
	} else if flag.NArg() != 0 {
		flag.Usage()
	}

	// Read target hosts from standard input
	var hosts []string
	buf := bufio.NewReader(os.Stdin)
	for {
		line, err := buf.ReadString('\n')
		if line != "" {
			line = strings.TrimSpace(line)
			hosts = append(hosts, line)
		}
		if err == io.EOF {
			break
		}
		if err != nil {
			fmt.Fprintf(os.Stderr, "Problem reading target hosts (%s)", err)
			os.Exit(1)
		}
	}

	// Log into each host and kill pertinent workers, using POSIX kill
	for _, h := range hosts {
		println("Hard-killing circuit worker(s) on", h)
		var killSh string
		if withID {
			killSh = fmt.Sprintf("ps ax | grep -i %s | grep -v grep | awk '{print $1}' | xargs kill -KILL\n", id.String())
		} else {
			killSh = fmt.Sprintf("ps ax | grep -i %s | grep -v grep | awk '{print $1}' | xargs kill -KILL\n", config.Config.Deploy.Worker)
		}
		_, stderr, err := posix.Exec("ssh", "", killSh, h, "sh")
		if err != nil {
			fmt.Fprintf(os.Stderr, "Problem while killing workers on %s (%s)\n", h, err)
			fmt.Fprintf(os.Stderr, "Remote shell error output:\n%s\n", stderr)
		}
	}
}