diff --git a/cmd/cmd.go b/cmd/cmd.go index 039da29e7..a5b754fe2 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -386,6 +386,9 @@ func initConfig() { // Load the config configfile.LoadConfig(ctx) + // Start accounting + accounting.Start(ctx) + // Hide console window if ci.NoConsole { terminal.HideConsole() diff --git a/fs/accounting/accounting.go b/fs/accounting/accounting.go index 2ffa37d49..65bbb82bb 100644 --- a/fs/accounting/accounting.go +++ b/fs/accounting/accounting.go @@ -29,6 +29,18 @@ var ErrorMaxTransferLimitReachedFatal = fserrors.FatalError(ErrorMaxTransferLimi // transfer limit is reached and a graceful stop is required. var ErrorMaxTransferLimitReachedGraceful = fserrors.NoRetryError(ErrorMaxTransferLimitReached) +// Start sets up the accounting, in particular the bandwidth limiting +func Start(ctx context.Context) { + // Start the token bucket limiter + TokenBucket.StartTokenBucket(ctx) + + // Start the bandwidth update ticker + TokenBucket.StartTokenTicker(ctx) + + // Start the transactions per second limiter + StartLimitTPS(ctx) +} + // Account limits and accounts for one transfer type Account struct { stats *StatsInfo diff --git a/fs/config/config.go b/fs/config/config.go index c68df35cc..9544ae9f2 100644 --- a/fs/config/config.go +++ b/fs/config/config.go @@ -21,7 +21,6 @@ import ( "github.com/pkg/errors" "github.com/rclone/rclone/fs" - "github.com/rclone/rclone/fs/accounting" "github.com/rclone/rclone/fs/config/configmap" "github.com/rclone/rclone/fs/config/configstruct" "github.com/rclone/rclone/fs/config/obscure" @@ -232,15 +231,6 @@ func LoadConfig(ctx context.Context) { } else { fs.Debugf(nil, "Using config file from %q", ConfigPath) } - - // Start the token bucket limiter - accounting.TokenBucket.StartTokenBucket(ctx) - - // Start the bandwidth update ticker - accounting.TokenBucket.StartTokenTicker(ctx) - - // Start the transactions per second limiter - accounting.StartLimitTPS(ctx) } // ErrorConfigFileNotFound is returned when the config file is not found diff --git a/fstest/fstest.go b/fstest/fstest.go index b894eb004..f97bc2cae 100644 --- a/fstest/fstest.go +++ b/fstest/fstest.go @@ -72,6 +72,7 @@ func Initialise() { config.ConfigPath = envConfig } configfile.LoadConfig(ctx) + accounting.Start(ctx) if *Verbose { ci.LogLevel = fs.LogLevelDebug }