summaryrefslogtreecommitdiff
path: root/src/Propellor/Property
diff options
context:
space:
mode:
authorJoey Hess2016-02-19 11:30:44 -0400
committerJoey Hess2016-02-19 11:30:44 -0400
commite6187fc80de701bee5db84bb13d5884b3ca34e77 (patch)
tree14439b193f94efbd7ec5d83311fb03728d87a7fe /src/Propellor/Property
parent935165d6c578c0116f65d18bfdc14203365e82cd (diff)
Obnam: Only let one backup job run at a time when a host has multiple different backup properties, to avoid concurrent jobs fighting over scarce resources (particularly memory). Other jobs block on a lock file.
Diffstat (limited to 'src/Propellor/Property')
-rw-r--r--src/Propellor/Property/Obnam.hs26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/Propellor/Property/Obnam.hs b/src/Propellor/Property/Obnam.hs
index 92c97f18..666328ac 100644
--- a/src/Propellor/Property/Obnam.hs
+++ b/src/Propellor/Property/Obnam.hs
@@ -36,6 +36,10 @@ data NumClients = OnlyClient | MultipleClients
--
-- Note that this property does not make obnam encrypt the backup
-- repository.
+--
+-- Since obnam uses a fair amount of system resources, only one obnam
+-- backup job will be run at a time. Other jobs will wait their turns to
+-- run.
backup :: FilePath -> Cron.Times -> [ObnamParam] -> NumClients -> Property NoInfo
backup dir crontimes params numclients =
backup' dir crontimes params numclients
@@ -59,16 +63,18 @@ backup' dir crontimes params numclients = cronjob `describe` desc
where
desc = dir ++ " backed up by obnam"
cronjob = Cron.niceJob ("obnam_backup" ++ dir) crontimes (User "root") "/" $
- unwords $ catMaybes
- [ if numclients == OnlyClient
- -- forcelock fails if repo does not exist yet
- then Just $ forcelockcmd ++ " 2>/dev/null ;"
- else Nothing
- , Just backupcmd
- , if any isKeepParam params
- then Just $ "&& " ++ forgetcmd
- else Nothing
- ]
+ "flock " ++ shellEscape lockfile ++ " sh -c " ++ shellEscape cmdline
+ lockfile = "/var/lock/propellor-obnam.lock"
+ cmdline = unwords $ catMaybes
+ [ if numclients == OnlyClient
+ -- forcelock fails if repo does not exist yet
+ then Just $ forcelockcmd ++ " 2>/dev/null ;"
+ else Nothing
+ , Just backupcmd
+ , if any isKeepParam params
+ then Just $ "&& " ++ forgetcmd
+ else Nothing
+ ]
forcelockcmd = unwords $
[ "obnam"
, "force-lock"