Skip to content

Commit

Permalink
Don't kill exec process immediately (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
btoews authored Jun 8, 2023
1 parent 18760d2 commit 2045363
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions cmd/litestream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,17 @@ func (m *Main) Run(ctx context.Context, args []string) (err error) {
}

// Setup signal handler.
ctx, cancel := context.WithCancel(ctx)
signalCh := signalChan()

if err := c.Run(ctx); err != nil {
if err := c.Run(); err != nil {
return err
}

// Wait for signal to stop program.
select {
case err = <-c.execCh:
cancel()
fmt.Println("subprocess exited, litestream shutting down")
case sig := <-signalCh:
cancel()
fmt.Println("signal received, litestream shutting down")

if c.cmd != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/litestream/replicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func (c *ReplicateCommand) ParseFlags(ctx context.Context, args []string) (err e
}

// Run loads all databases specified in the configuration.
func (c *ReplicateCommand) Run(ctx context.Context) (err error) {
func (c *ReplicateCommand) Run() (err error) {
// Display version information.
log.Printf("litestream %s", Version)

Expand Down Expand Up @@ -162,7 +162,7 @@ func (c *ReplicateCommand) Run(ctx context.Context) (err error) {
return fmt.Errorf("cannot parse exec command: %w", err)
}

c.cmd = exec.CommandContext(ctx, execArgs[0], execArgs[1:]...)
c.cmd = exec.Command(execArgs[0], execArgs[1:]...)
c.cmd.Env = os.Environ()
c.cmd.Stdout = os.Stdout
c.cmd.Stderr = os.Stderr
Expand Down

0 comments on commit 2045363

Please sign in to comment.