Don't kill exec process immediately (#484)

This commit is contained in:
Ben Toews
2023-06-08 10:57:50 -06:00
committed by GitHub
parent 18760d2a7a
commit 2045363cd1
2 changed files with 3 additions and 6 deletions

View File

@@ -86,20 +86,17 @@ func (m *Main) Run(ctx context.Context, args []string) (err error) {
} }
// Setup signal handler. // Setup signal handler.
ctx, cancel := context.WithCancel(ctx)
signalCh := signalChan() signalCh := signalChan()
if err := c.Run(ctx); err != nil { if err := c.Run(); err != nil {
return err return err
} }
// Wait for signal to stop program. // Wait for signal to stop program.
select { select {
case err = <-c.execCh: case err = <-c.execCh:
cancel()
fmt.Println("subprocess exited, litestream shutting down") fmt.Println("subprocess exited, litestream shutting down")
case sig := <-signalCh: case sig := <-signalCh:
cancel()
fmt.Println("signal received, litestream shutting down") fmt.Println("signal received, litestream shutting down")
if c.cmd != nil { if c.cmd != nil {

View File

@@ -94,7 +94,7 @@ func (c *ReplicateCommand) ParseFlags(ctx context.Context, args []string) (err e
} }
// Run loads all databases specified in the configuration. // 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. // Display version information.
log.Printf("litestream %s", Version) log.Printf("litestream %s", Version)
@@ -162,7 +162,7 @@ func (c *ReplicateCommand) Run(ctx context.Context) (err error) {
return fmt.Errorf("cannot parse exec command: %w", err) 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.Env = os.Environ()
c.cmd.Stdout = os.Stdout c.cmd.Stdout = os.Stdout
c.cmd.Stderr = os.Stderr c.cmd.Stderr = os.Stderr