We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 38c9cb0 commit 8d3c46eCopy full SHA for 8d3c46e
pkg/kbagent/service/command.go
@@ -28,6 +28,7 @@ import (
28
"os"
29
"os/exec"
30
"strings"
31
+ "syscall"
32
"time"
33
34
"github.com/apecloud/kubeblocks/pkg/kbagent/proto"
@@ -144,6 +145,11 @@ func runCommandX(ctx context.Context, action *proto.ExecAction, parameters map[s
144
145
cmd.Stdin = stdinReader
146
cmd.Stdout = stdoutWriter
147
cmd.Stderr = stderrWriter
148
+ cmd.WaitDelay = time.Second * 1
149
+ // gracefully terminate, go will kill it after waitDelay
150
+ cmd.Cancel = func() error {
151
+ return cmd.Process.Signal(syscall.SIGTERM)
152
+ }
153
154
errChan := make(chan error, 1)
155
go func() {
pkg/kbagent/service/command_test.go
@@ -271,22 +271,20 @@ var _ = Describe("command", func() {
271
action := &proto.ExecAction{
272
Commands: []string{"/bin/bash", "-c", "command-not-found"},
273
}
274
- output, err := runCommand(ctx, action, nil, nil)
+ _, err := runCommand(ctx, action, nil, nil)
275
Expect(err).ShouldNot(BeNil())
276
Expect(errors.Is(err, proto.ErrFailed)).Should(BeTrue())
277
Expect(err.Error()).Should(ContainSubstring("command not found"))
278
- Expect(output).Should(BeNil())
279
})
280
281
It("timeout", func() {
282
283
Commands: []string{"/bin/bash", "-c", "sleep 60"},
284
285
timeout := int32(1)
286
- output, err := runCommand(ctx, action, nil, &timeout)
+ _, err := runCommand(ctx, action, nil, &timeout)
287
288
Expect(errors.Is(err, proto.ErrTimedOut)).Should(BeTrue())
289
290
291
292
0 commit comments