mirror of
https://github.com/rclone/rclone.git
synced 2025-08-13 23:38:51 +02:00
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:
committed by
Nick Craig-Wood
parent
062616e4dd
commit
cc4f5ba7ba
35
fs/accounting_unix.go
Normal file
35
fs/accounting_unix.go
Normal 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
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
Reference in New Issue
Block a user