summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoey Hess2017-07-28 11:47:13 -0400
committerJoey Hess2017-07-28 11:47:13 -0400
commit417412207725a3c99c6fd9871eab8080356b20b2 (patch)
tree150f416d818590111f07cbeece4e28e8a54433c9 /src
parent93e8d4c41b7f125f755775707c0277a72437cf36 (diff)
parent1eaf855e5f5ac35300c092034d4e7504cc232e6e (diff)
Merge branch 'joeyconfig'
Diffstat (limited to 'src')
-rw-r--r--src/Propellor/Property/Systemd.hs64
1 files changed, 26 insertions, 38 deletions
diff --git a/src/Propellor/Property/Systemd.hs b/src/Propellor/Property/Systemd.hs
index d1a94aa8..51d1313c 100644
--- a/src/Propellor/Property/Systemd.hs
+++ b/src/Propellor/Property/Systemd.hs
@@ -283,54 +283,42 @@ nspawned c@(Container name (Chroot.Chroot loc builder _ _) h) =
chroot = Chroot.Chroot loc builder Chroot.propagateChrootInfo h
--- | Sets up the service file for the container, and then starts
--- it running.
+-- | Sets up the service files for the container, using the
+-- systemd-nspawn@.service template, and starts it running.
nspawnService :: Container -> ChrootCfg -> RevertableProperty Linux Linux
nspawnService (Container name _ _) cfg = setup <!> teardown
where
service = nspawnServiceName name
- servicefile = "/etc/systemd/system/multi-user.target.wants" </> service
-
- servicefilecontent = do
- ls <- lines <$> readFile "/lib/systemd/system/systemd-nspawn@.service"
- return $ unlines $
- "# deployed by propellor" : map addparams ls
- addparams l
- | "ExecStart=" `isPrefixOf` l = unwords $
- [ "ExecStart = /usr/bin/systemd-nspawn"
- , "--quiet"
- , "--keep-unit"
- , "--boot"
- , "--directory=" ++ containerDir name
- , "--machine=%i"
- ] ++ nspawnServiceParams cfg
- | otherwise = l
-
- goodservicefile = (==)
- <$> servicefilecontent
- <*> catchDefaultIO "" (readFile servicefile)
-
- writeservicefile :: Property Linux
- writeservicefile = property servicefile $ makeChange $ do
- c <- servicefilecontent
- File.viaStableTmp (\t -> writeFile t c) servicefile
-
- setupservicefile :: Property Linux
- setupservicefile = check (not <$> goodservicefile) $
- -- if it's running, it has the wrong configuration,
- -- so stop it
- stopped service
- `requires` daemonReloaded
- `requires` writeservicefile
+ overridedir = "/etc/systemd/system" </> nspawnServiceName name ++ ".d"
+ overridefile = overridedir </> "local.conf"
+ overridecontent =
+ [ "[Service]"
+ , "# Reset ExecStart from the template"
+ , "ExecStart="
+ , "ExecStart=/usr/bin/systemd-nspawn " ++ unwords nspawnparams
+ ]
+ nspawnparams =
+ [ "--quiet"
+ , "--keep-unit"
+ , "--boot"
+ , "--directory=" ++ containerDir name
+ , "--machine=" ++ name
+ ] ++ nspawnServiceParams cfg
+
+ overrideconfigured = File.hasContent overridefile overridecontent
+ `onChange` daemonReloaded
+ `requires` File.dirExists overridedir
setup :: Property Linux
setup = started service
- `requires` setupservicefile
+ `requires` enabled service
+ `requires` overrideconfigured
`requires` machined
teardown :: Property Linux
- teardown = check (doesFileExist servicefile) $
- disabled service `requires` stopped service
+ teardown = stopped service
+ `before` disabled service
+ `before` File.notPresent overridefile
nspawnServiceParams :: ChrootCfg -> [String]
nspawnServiceParams NoChrootCfg = []