From 4ac4946095213d617adde6b5e7067298c61e6df9 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Mon, 27 Jul 2020 17:48:19 -0700 Subject: [PATCH] Fix race: Re-register on file change --- modules/syncthing-autoregister.nix | 14 ++++++++++++++ tests/automatic-enrollment.nix | 6 +++--- 2 files changed, 17 insertions(+), 3 deletions(-) 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") ''; }) -- 2.44.1