A daemon that automatically manages certain aspects of the Syncthing configuration.
  • Go 98.5%
  • Makefile 1.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2024-08-14 08:07:22 +02:00
.github fix: correct build tags 2024-08-14 08:07:22 +02:00
cmd/syncthing-configd fix: handle absense of garbage collect config 2024-08-08 12:17:54 +02:00
doc docs: Update sequence diagram 2023-12-18 11:24:28 +01:00
etc chore: remove unused systemd things 2024-08-08 12:20:40 +02:00
internal chore: remove unused Mode type 2024-08-08 12:07:08 +02:00
proto chore: remove unused Mode type 2024-08-08 12:07:08 +02:00
.gitignore build: Build Debian package 2023-12-14 12:42:57 +01:00
.ko.yaml build: build and publish using ko 2024-08-08 12:00:08 +02:00
CONTRIBUTING.md docs: add CONTRIBUTING 2024-08-08 12:28:43 +02:00
go.mod build: update dependencies 2024-08-12 08:42:43 +02:00
go.sum build: update dependencies 2024-08-12 08:42:43 +02:00
LICENSE docs: Add LICENSE 2023-12-14 12:42:55 +01:00
Makefile build: build and publish using ko 2024-08-08 12:00:08 +02:00
README.md docs: link to sample config file 2024-08-08 12:20:49 +02:00

Syncthing-Configd

A daemon that automatically manages certain aspects of the Syncthing configuration.

Principle of operation

Syncthing-Configd is a sidecar process to Syncthing itself. It listens to events, processes them according to a configured ruleset, and applies configuration changes to Syncthing accordingly.

Usage

Configuration

There is a sample configuration file in the repository.

A configuration file contains the Syncthing instance(s) to connect to, patterns to apply to incoming device connections, and other directives. Initially, one or more syncthing sections defines the Syncthing instance(s) to connect to:

syncthing {
    address: "127.0.0.1:8081"
    api_key: "abc123"
}
syncthing {
    address: "127.0.0.1:8082"
    api_key: "abc123"
}

Adding devices and folders

The daemon listens to Syncthing events informing it of of "rejected devices". A device is rejected when an incoming connection is received but Syncthing is not configured to accept a connection from that device.

For each rejected device it checks the configured patterns to see if source address matches a known network. If so, it applies the pattern to add the device and share the relates set of folders with it. Folders can be created if they don't exist beforehand, with a pattern for the ID and path.

Patterns are defined in the configuration file:

pattern {
    # Accept devices from 172.16.32.0/24
    accept_cidr: "172.16.32.0/24"
    accept_cidr: "127.0.0.0/8"

    settings {
        max_send_kbps: 250
        max_recv_kbps: 150
        num_connections: 1
        max_request_kib: 1024
    }

    # Assign them the folder "default".
    folder {
        id: "default"
    }

    # Also an individual folder for each device. The `settings` are used if
    # the folder needs to be created, otherwise the device is simply added
    # to the existing folder configuration.
    folder {
        id: "${name}"
        settings {
            label: "Device ${name}'s folder"
            type: SEND_RECEIVE
            path: "/var/device-folders/${name}"
            fs_watcher_disabled: true
            rescan_interval_s: 86400
            case_sensitive_fs: true
            ignore_permissions: true
        }
    }
}

# Another pattern accepts devices from 10.0.0.0/8 and shares the "images"
# folder with them.
pattern {
    accept_cidr: "10.0.0.0/8"
    folder {
        id: "images"
    }
}

For the full range of settings, please see the Protobuf definition. In general it closely mirrors the config options of Syncthing itself.

Garbage collecting unused device & folders

Devices and folders that are no longer in use can be automatically removed. Devices are removed if they have not been "seen" (i.e., had an active connection) for a given number of days. Folders are removed if they are not shared with any other device -- typically, after a device has been removed.

garbage_collect {
    run_every_s: 86400  # once a day, midnight UTC
    unseen_devices_days: 90
    unshared_folders: true
}

Installation

Docker Image

It's easiest to use the precompiled Docker image. Assuming a configuration file in /etc/syncthing-configd/configd.conf, something like the command below will start syncthing-configd.

% docker run -d --restart always --name syncthing-configd \
    -v /etc/syncthing-configd/configd.conf:/etc/syncthing-configd/configd.conf \
    ghcr.io/kastelo/syncthing-configd:latest

Note that since a Docker container runs in a separate namespace it will not be able to access a Syncthing instance on the same machine by using the 127.0.0.1 address.


Copyright © Kastelo AB. Licensed under the Mozilla Public License Version 2.0.