Skip to content

Commit

Permalink
Update badger.go
Browse files Browse the repository at this point in the history
  • Loading branch information
chiefMarlin authored Jan 12, 2025
1 parent 12c6d33 commit 1ba2dd0
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions badger.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,23 +143,37 @@ func coordinator() {
}

func executor(d string, ctx context.Context, daemon bool) {
for {
tlog("info", fmt.Sprintf("[%s] => [STARTED]", d))
out, err := exec.CommandContext(ctx, "/bin/bash", "-u", "-o", "pipefail", "-c", d).Output()
if err != nil {
tlog("error", fmt.Sprintf("[%s] => [KILLED] | [%s] %s", d, err, out))
if ctx.Err() != nil {
if ctx.Err().Error() == "context canceled" {
return
}
}
}
if !daemon {
return
}
tlog("info", fmt.Sprintf("[%s] => [EXITED]", d))
time.Sleep(3 * time.Second)
}
// Determine shell and args
shellCmd := "/bin/sh"
shellArgs := []string{"-c"}

// Check for bash and use it if available
if _, err := os.Stat("/bin/bash"); err == nil {
shellCmd = "/bin/bash"
shellArgs = []string{"-u", "-o", "pipefail", "-c"}
} else if _, err := os.Stat("/usr/local/bin/bash"); err == nil {
// Check FreeBSD common bash location
shellCmd = "/usr/local/bin/bash"
shellArgs = []string{"-u", "-o", "pipefail", "-c"}
}

for {
tlog("info", fmt.Sprintf("[%s] => [STARTED]", d))
out, err := exec.CommandContext(ctx, shellCmd, append(shellArgs, d)...).Output()
if err != nil {
tlog("error", fmt.Sprintf("[%s] => [KILLED] | [%s] %s", d, err, out))
if ctx.Err() != nil {
if ctx.Err().Error() == "context canceled" {
return
}
}
}
if !daemon {
return
}
tlog("info", fmt.Sprintf("[%s] => [EXITED]", d))
time.Sleep(3 * time.Second)
}
}

func getSignal() {
Expand Down

0 comments on commit 1ba2dd0

Please sign in to comment.