Add support to toggle bandwidth limits via SIGUSR2.

Sending rclone a SIGUSR2 signal will toggle the limiter between off and
the limit set with the --bwlimit command-line option.
This commit is contained in:
Marco Paganini
2016-10-22 00:21:28 -07:00
committed by Nick Craig-Wood
parent 062616e4dd
commit cc4f5ba7ba
4 changed files with 71 additions and 2 deletions

35
fs/accounting_unix.go Normal file
View File

@ -0,0 +1,35 @@
// Accounting and limiting reader
// Unix specific functions.
// +build darwin dragonfly freebsd linux netbsd openbsd
package fs
import (
"os"
"os/signal"
"syscall"
)
// startSignalHandler() sets a signal handler to catch SIGUSR2 and toggle throttling.
func startSignalHandler() {
// Don't do anything if no bandwidth limits requested.
if bwLimit <= 0 {
return
}
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGUSR2)
go func() {
// This runs forever, but blocks until the signal is received.
for {
<-signals
if tokenBucket == nil {
tokenBucket = origTokenBucket
} else {
tokenBucket = nil
}
}
}()
}