summaryrefslogtreecommitdiffstats
path: root/src/dma/cmd/server/agent.go
blob: ffcb4a9725a8480b88243879638de311f14a5f51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main

import (
	"fmt"
	"os/exec"
	"strings"
)

func createCollectdConf() error {
	outStatus, errStatus := exec.Command("ssh", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "localhost", "sudo", "systemctl", "status", "collectd").Output()
	if errStatus != nil {
		return fmt.Errorf("status NG")
	}
	if !strings.Contains(string(outStatus), "running") {
		return fmt.Errorf("status not running")
	}

	_, errStop := exec.Command("ssh", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "localhost", "sudo", "systemctl", "stop", "collectd").Output()
	if errStop != nil {
		return fmt.Errorf("stop NG")
	}

	_, errStart := exec.Command("ssh", "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null", "localhost", "sudo", "systemctl", "start", "collectd").Output()
	if errStart != nil {
		return fmt.Errorf("start NG")
	}

	fmt.Println("All complete!")

	return nil
}