From: Scott Worley Date: Tue, 28 Jul 2020 00:48:19 +0000 (-0700) Subject: Fix race: Re-register on file change X-Git-Url: http://git.scottworley.com/syncthing-autoregister/commitdiff_plain/4ac4946095213d617adde6b5e7067298c61e6df9 Fix race: Re-register on file change --- diff --git a/modules/syncthing-autoregister.nix b/modules/syncthing-autoregister.nix index da9df86..ad710f6 100644 --- a/modules/syncthing-autoregister.nix +++ b/modules/syncthing-autoregister.nix @@ -45,6 +45,20 @@ in { ExecStart = register-script; }; }; + systemd.services.syncthing-reregister = { + after = [ "syncthing-autoregister.service" ]; + script = '' + ${pkgs.coreutils}/bin/sleep 1 + ${pkgs.systemd}/bin/systemctl restart syncthing-autoregister + ''; + serviceConfig = { + Type = "oneshot"; + }; + }; + systemd.paths.syncthing-reregister = { + pathConfig.PathChanged = cfg.path; + wantedBy = [ "multi-user.target" ]; + }; }; } diff --git a/tests/automatic-enrollment.nix b/tests/automatic-enrollment.nix index 951a415..617f672 100644 --- a/tests/automatic-enrollment.nix +++ b/tests/automatic-enrollment.nix @@ -57,7 +57,7 @@ import ({ pkgs, lib, ... }: def verifyDeviceIDSet(machine, expectedDevice): - machine.succeed( + machine.wait_until_succeeds( '(( "$(nix eval --raw -f "" config.services.syncthing.declarative.devices.%s.id | wc -c)" == 63 ))' % expectedDevice ) @@ -82,16 +82,16 @@ import ({ pkgs, lib, ... }: "${configurationWithDeviceIDs}" ) + start_all() a.wait_for_unit("syncthing-autoregister.service") setConfig(a, configurationWithDeviceIDs) verifyDeviceIDSet(a, "a") getDeviceFile(a) + b.wait_for_unit("syncthing-autoregister.service") putDeviceFile(b) setConfig(b, configurationWithDeviceIDs) verifyDeviceIDSet(b, "a") - b.wait_for_unit("syncthing-autoregister.service") - verifyDeviceIDSet(b, "a") verifyDeviceIDSet(b, "b") ''; })