git.iko.soy/typeable/nixpkgs
on master help sign in
nixos: tarsnap - make systemd timer persistent

A machine may not always be active (or online!) when a backup timer triggers, meaning backups can be missed - now we properly set the tarsnap timer's Persistent option so systemd will run the command even when the machine wasn't online at that exact time. However, we also need to make sure that we can contact the tarsnap server reliably before we start the backup. So, we attempt to ping the access endpoint in a loop with a sleep, before continuing. This fixes #8823. Signed-off-by: Austin Seipp <aseipp@pobox.com>

commitad796f155bc2e44d6944f002ad95596e39711670 authorTanner Doshier <doshitan@gmail.com> dateThu 7 Jan 2016, 05:06 (11 years ago) parenta68450e
1 file changed+13−2
nixos/modules/services/backup/tarsnap.nix+13−2
nixos/modules/services/backup/tarsnap.nix+13−2
@@ -242,9 +242,16 @@ in
242242
243243 systemd.services."tarsnap@" = {
244244 description = "Tarsnap archive '%i'";
245− requires = [ "network.target" ];
245+ requires = [ "network-online.target" ];
246+ after = [ "network-online.target" ];
246247
247− path = [ pkgs.tarsnap pkgs.coreutils ];
248+ path = [ pkgs.iputils pkgs.tarsnap pkgs.coreutils ];
249+
250+ # In order for the persistent tarsnap timer to work reliably, we have to
251+ # make sure that the tarsnap server is reachable after systemd starts up
252+ # the service - therefore we sleep in a loop until we can ping the
253+ # endpoint.
254+ preStart = "while ! ping -q -c 1 betatest-server.tarsnap.com &> /dev/null; do sleep 3; done";
248255 scriptArgs = "%i";
249256 script = ''
250257 mkdir -p -m 0755 ${dirOf cfg.cachedir}
@@ -259,11 +266,15 @@ in
259266 IOSchedulingClass = "idle";
260267 NoNewPrivileges = "true";
261268 CapabilityBoundingSet = "CAP_DAC_READ_SEARCH";
269+ PermissionsStartOnly = "true";
262270 };
263271 };
264272
273+ # Note: the timer must be Persistent=true, so that systemd will start it even
274+ # if e.g. your laptop was asleep while the latest interval occurred.
265275 systemd.timers = mapAttrs' (name: cfg: nameValuePair "tarsnap@${name}"
266276 { timerConfig.OnCalendar = cfg.period;
277+ timerConfig.Persistent = "true";
267278 wantedBy = [ "timers.target" ];
268279 }) cfg.archives;
269280