Skip to content

Commit 1ba2dd0

Browse files
authored
Update badger.go
1 parent 12c6d33 commit 1ba2dd0

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

badger.go

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,37 @@ func coordinator() {
143143
}
144144

145145
func executor(d string, ctx context.Context, daemon bool) {
146-
for {
147-
tlog("info", fmt.Sprintf("[%s] => [STARTED]", d))
148-
out, err := exec.CommandContext(ctx, "/bin/bash", "-u", "-o", "pipefail", "-c", d).Output()
149-
if err != nil {
150-
tlog("error", fmt.Sprintf("[%s] => [KILLED] | [%s] %s", d, err, out))
151-
if ctx.Err() != nil {
152-
if ctx.Err().Error() == "context canceled" {
153-
return
154-
}
155-
}
156-
}
157-
if !daemon {
158-
return
159-
}
160-
tlog("info", fmt.Sprintf("[%s] => [EXITED]", d))
161-
time.Sleep(3 * time.Second)
162-
}
146+
// Determine shell and args
147+
shellCmd := "/bin/sh"
148+
shellArgs := []string{"-c"}
149+
150+
// Check for bash and use it if available
151+
if _, err := os.Stat("/bin/bash"); err == nil {
152+
shellCmd = "/bin/bash"
153+
shellArgs = []string{"-u", "-o", "pipefail", "-c"}
154+
} else if _, err := os.Stat("/usr/local/bin/bash"); err == nil {
155+
// Check FreeBSD common bash location
156+
shellCmd = "/usr/local/bin/bash"
157+
shellArgs = []string{"-u", "-o", "pipefail", "-c"}
158+
}
159+
160+
for {
161+
tlog("info", fmt.Sprintf("[%s] => [STARTED]", d))
162+
out, err := exec.CommandContext(ctx, shellCmd, append(shellArgs, d)...).Output()
163+
if err != nil {
164+
tlog("error", fmt.Sprintf("[%s] => [KILLED] | [%s] %s", d, err, out))
165+
if ctx.Err() != nil {
166+
if ctx.Err().Error() == "context canceled" {
167+
return
168+
}
169+
}
170+
}
171+
if !daemon {
172+
return
173+
}
174+
tlog("info", fmt.Sprintf("[%s] => [EXITED]", d))
175+
time.Sleep(3 * time.Second)
176+
}
163177
}
164178

165179
func getSignal() {

0 commit comments

Comments
 (0)