diff options
| author | Joey Hess <joeyh@joeyh.name> | 2017-07-27 17:06:07 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2017-07-27 17:06:07 -0400 |
| commit | eb5e568fb851e89569e42509d2dd476457fc09ea (patch) | |
| tree | ea58c0d4de9c225d699696e978f2222b65223259 /src/Propellor/Property/Systemd.hs | |
| parent | 9819b527c61fc6b4d2ac49a6f1c2a4910772636f (diff) | |
propellor spin
Diffstat (limited to 'src/Propellor/Property/Systemd.hs')
| -rw-r--r-- | src/Propellor/Property/Systemd.hs | 60 |
1 files changed, 23 insertions, 37 deletions
diff --git a/src/Propellor/Property/Systemd.hs b/src/Propellor/Property/Systemd.hs index d1a94aa8..473b2f39 100644 --- a/src/Propellor/Property/Systemd.hs +++ b/src/Propellor/Property/Systemd.hs @@ -283,54 +283,40 @@ 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 + overridedir = "/etc/systemd/system" </> nspawnServiceName name ++ ".d" + overridefile = overridedir </> "local.conf" + overridecontent = + [ "[Service]" + , "ExecStart=/usr/bin/systemd-nspawn " ++ unwords nspawnparams + ] + nspawnparams = + [ "--quiet" + , "--keep-unit" + , "--boot" + , "--directory=" ++ containerDir name + , "--machine=" ++ name + ] ++ nspawnServiceParams cfg - 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 + 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 = [] |
