Address @yegortimoshenko review

This commit is contained in:
Michishige Kaito 2018-03-27 16:35:54 +01:00
parent bde525aaaf
commit c515f7036e

View File

@ -304,7 +304,7 @@ in
requires = [ "network-online.target" ]; requires = [ "network-online.target" ];
after = [ "network-online.target" ]; after = [ "network-online.target" ];
path = [ pkgs.iputils pkgs.tarsnap pkgs.utillinux ]; path = with pkgs; [ iputils tarsnap utillinux ];
# In order for the persistent tarsnap timer to work reliably, we have to # In order for the persistent tarsnap timer to work reliably, we have to
# make sure that the tarsnap server is reachable after systemd starts up # make sure that the tarsnap server is reachable after systemd starts up
@ -314,9 +314,9 @@ in
while ! ping -q -c 1 v1-0-0-server.tarsnap.com &> /dev/null; do sleep 3; done while ! ping -q -c 1 v1-0-0-server.tarsnap.com &> /dev/null; do sleep 3; done
''; '';
script = script = let
let run = ''tarsnap --configfile "/etc/tarsnap/${name}.conf" \ tarsnap = ''tarsnap --configfile "/etc/tarsnap/${name}.conf"'';
-c -f "${name}-$(date +"%Y%m%d%H%M%S")" \ run = ''${tarsnap} -c -f "${name}-$(date +"%Y%m%d%H%M%S")" \
${optionalString cfg.verbose "-v"} \ ${optionalString cfg.verbose "-v"} \
${optionalString cfg.explicitSymlinks "-H"} \ ${optionalString cfg.explicitSymlinks "-H"} \
${optionalString cfg.followSymlinks "-L"} \ ${optionalString cfg.followSymlinks "-L"} \
@ -329,7 +329,7 @@ in
if [ ! -e ${cfg.cachedir}/firstrun ]; then if [ ! -e ${cfg.cachedir}/firstrun ]; then
( flock 10 ( flock 10
flock -u 9 flock -u 9
tarsnap --configfile "/etc/tarsnap/${name}.conf" --fsck ${tarsnap} --fsck
flock 9 flock 9
) 10>${cfg.cachedir}/firstrun ) 10>${cfg.cachedir}/firstrun
fi fi
@ -351,35 +351,29 @@ in
description = "Tarsnap restore '${name}'"; description = "Tarsnap restore '${name}'";
requires = [ "network-online.target" ]; requires = [ "network-online.target" ];
path = [ pkgs.iputils pkgs.tarsnap pkgs.utillinux ]; path = with pkgs; [ iputils tarsnap utillinux ];
## script = let
preStart = ''
while ! ping -q -c 1 v1-0-0-server.tarsnap.com &> /dev/null; do sleep 3; done
'';
script =
let
tarsnap = ''tarsnap --configfile "/etc/tarsnap/${name}.conf"''; tarsnap = ''tarsnap --configfile "/etc/tarsnap/${name}.conf"'';
lastArchive = ''$(${tarsnap} --list-archives | sort | tail -1)''; lastArchive = ''$(${tarsnap} --list-archives | sort | tail -1)'';
run = ''${tarsnap} -x -f "${lastArchive}" ${optionalString cfg.verbose "-v"}''; run = ''${tarsnap} -x -f "${lastArchive}" ${optionalString cfg.verbose "-v"}'';
in if (cfg.cachedir != null) then '' in if (cfg.cachedir != null) then ''
mkdir -p ${cfg.cachedir} mkdir -p ${cfg.cachedir}
chmod 0700 ${cfg.cachedir} chmod 0700 ${cfg.cachedir}
( flock 9 ( flock 9
if [ ! -e ${cfg.cachedir}/firstrun ]; then if [ ! -e ${cfg.cachedir}/firstrun ]; then
( flock 10 ( flock 10
flock -u 9 flock -u 9
${tarsnap} --fsck ${tarsnap} --fsck
flock 9 flock 9
) 10>${cfg.cachedir}/firstrun ) 10>${cfg.cachedir}/firstrun
fi fi
) 9>${cfg.cachedir}/lockf ) 9>${cfg.cachedir}/lockf
exec flock ${cfg.cachedir}/firstrun ${run} exec flock ${cfg.cachedir}/firstrun ${run}
'' else "exec ${run}"; '' else "exec ${run}";
serviceConfig = { serviceConfig = {
Type = "oneshot"; Type = "oneshot";