| 76 | } |
| 77 | |
| 78 | func (w *Watcher) runCommands() bool { |
| 79 | result := true |
| 80 | w.errorLog = "" |
| 81 | for _, command := range w.config.Commands { |
| 82 | var outBuffer, errBuffer bytes.Buffer |
| 83 | cmd := exec.Command("sh", "-c", command) |
| 84 | cmd.Stdout = &outBuffer |
| 85 | cmd.Stderr = &errBuffer |
| 86 | err := cmd.Run() |
| 87 | if err != nil { |
| 88 | w.errorLog += fmt.Sprintf("[%s]:\n%s%s", command, outBuffer.String(), errBuffer.String()) |
| 89 | result = false |
| 90 | if w.config.BreakOnFail { |
| 91 | break |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | return result |
| 96 | } |
| 97 | |
| 98 | // GetStatus returns text representation of current watcher's status |
| 99 | func (w *Watcher) GetStatus() string { |