Skip to content

Commit

Permalink
Make SIGTERM graceful stop zrepl
Browse files Browse the repository at this point in the history
  • Loading branch information
dsh2dsh committed Nov 27, 2024
1 parent 8f46550 commit e4b2e6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,17 @@ pkg install zrepl-dsh2dsh

* New command `zrepl signal stop`

Stop the daemon right now. Actually it's the same like sending `SIGTERM` or
`SIGINT` to the daemon.
Stop the daemon right now. Actually it's the same like sending `SIGINT` to
the daemon.

* New command `zrepl signal shutdown`

Stop the daemon gracefully. After this signal, zrepl daemon will exit as
soon as it'll be safe. It interrupts any operation, except replication
steps. The daemon will wait for all replication steps completed and exit.

Sending `SIGTERM` has the same effect.

* Redesigned `zrepl status`

* `zfs send -w` is default now. Example how to change it back:
Expand Down
7 changes: 7 additions & 0 deletions internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ func waitDone(ctx context.Context, jobs *jobs) {
sigReload := make(chan os.Signal, 1)
signal.Notify(sigReload, syscall.SIGHUP)

sigTerm := make(chan os.Signal, 1)
signal.Reset(syscall.SIGTERM)
signal.Notify(sigTerm, syscall.SIGTERM)

log := logging.FromContext(ctx)
log.Info("waiting for jobs to finish")
wait := jobs.wait()
Expand All @@ -134,6 +138,9 @@ func waitDone(ctx context.Context, jobs *jobs) {
case <-sigReload:
log.Info("got HUP signal")
jobs.Reload()
case <-sigTerm:
log.Info("got TERM signal")
jobs.Shutdown()
}
}
}

0 comments on commit e4b2e6a

Please sign in to comment.