When is config.xml reloaded

When i manually or through a script change the ~/.config/syncthing/config.xml Syncthing does not seem to pick it up without a restart. Is this by design or a bug?

I am trying to set the bandwitdh limits maxSendKbps and maxRecvKbps during daytime and then by night, I change them back to 0 to have full speed in case there are big files to be transferred.

Or is it so that the configuration actually changes but the GUI isn’t updating the values?

The config file is only read on startup. To change the config while running, use the REST interface to POST a new config.

Thanks, I will try that.

Yep, it worked! Here is a Python script that dows this in case anyone else need something similar:

#!/usr/bin/env python3
import argparse
import json
import logging
import requests

BASEURL = 'http://localhost:8384'
URL_CONFIG = f'{BASEURL}/rest/system/config'
URL_RESTART = f'{BASEURL}/rest/system/restart'
log = logging.getLogger(__name__)
log.addHandler(logging.NullHandler())


def parse_sys_args():
    parser = argparse.ArgumentParser()
    parser.add_argument('api_key', help='Syncthing api key')
    parser.add_argument('-r', '--recieve', default=0, type=int,
                        help='Max recieve kbps value, default=0')
    parser.add_argument('-s', '--send', default=0, type=int,
                        help='Max send kbps value, default=0')
    parser.add_argument('-v', '--verbose', action='store_true')
    return parser.parse_args()


def get_config(api_key):
    r = requests.get(URL_CONFIG, headers={'X-API-Key': api_key})
    config = r.json()
    log.debug('Got config:\n' + json.dumps(config, sort_keys=True, indent=4))
    return config


def set_config(api_key, config):
    log.info('Updating Syncthing configuration')
    log.debug('Set config:\n' + json.dumps(config, sort_keys=True, indent=4))
    r = requests.post(URL_CONFIG, headers={'X-API-Key': api_key}, json=config)
    log.debug('Response: ' + r.text)


def restart(api_key):
    log.info('Restarting Syncthing')
    r = requests.post(URL_RESTART, headers={'X-API-Key': api_key})
    log.debug(r.text)


def main():
    args = parse_sys_args()

    log = logging.getLogger(__file__)
    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
    log.debug(args)

    config = get_config(args.api_key)
    config['options']['maxSendKbps'] = args.send
    config['options']['maxRecvKbps'] = args.recieve
    set_config(args.api_key, config)


if __name__ == '__main__':
    main()

Thanks for an awesome app!

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.