Skip to content

Commit

Permalink
let ansible-runner shut down gracefully on timeout
Browse files Browse the repository at this point in the history
Signed-off-by: Dasha Komsa <komsa.darya@gmail.com>
  • Loading branch information
d-honeybadger committed Jan 24, 2024
1 parent 5e0d992 commit 808976e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/ansible/ansible.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"os/exec"
"os/user"
"path/filepath"
"time"

"github.com/apenella/go-ansible/pkg/stdoutcallback/results"
"github.com/crossplane-contrib/provider-ansible/apis/v1alpha1"
Expand Down Expand Up @@ -358,6 +359,14 @@ func (r *Runner) Run() (*exec.Cmd, io.Reader, error) {
dc.Stdout = stdoutWriter
dc.Stderr = stderrWriter

// let the command shut down gracefully
dc.Cancel = func() error {
return dc.Process.Signal(os.Interrupt)
}
// if it doesn't respond to the SIGINT within 10s,
// it's going to be forcefully shut down with SIGKILL
dc.WaitDelay = 10 * time.Second

err := dc.Start()
if err != nil {
return nil, nil, err
Expand Down

0 comments on commit 808976e

Please sign in to comment.