From 0ee04ecc43e047b00437fb660e71f7dd67dd3afc Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 24 Jan 2015 22:38:10 -0400 Subject: GADT properties seem to work (untested) * Property has been converted to a GADT, and will be Property NoInfo or Property HasInfo. This was done to make sure that ensureProperty is only used on properties that do not have Info. Transition guide: - Change all "Property" to "Property NoInfo" or "Property WithInfo" (The compiler can tell you if you got it wrong!) - To construct a RevertableProperty, it is useful to use the new () operator - Constructing a list of properties can be problimatic, since Property NoInto and Property WithInfo are different types and cannot appear in the same list. To deal with this, "props" has been added, and can built up a list of properties of different types, using the same (&) and (!) operators that are used to build up a host's properties. --- src/Propellor/Property/Systemd.hs | 43 ++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'src/Propellor/Property/Systemd.hs') diff --git a/src/Propellor/Property/Systemd.hs b/src/Propellor/Property/Systemd.hs index 259bb222..07cf81ee 100644 --- a/src/Propellor/Property/Systemd.hs +++ b/src/Propellor/Property/Systemd.hs @@ -45,32 +45,32 @@ instance PropAccum Container where getProperties (Container _ _ h) = hostProperties h -- | Starts a systemd service. -started :: ServiceName -> Property +started :: ServiceName -> Property NoInfo started n = trivial $ cmdProperty "systemctl" ["start", n] `describe` ("service " ++ n ++ " started") -- | Stops a systemd service. -stopped :: ServiceName -> Property +stopped :: ServiceName -> Property NoInfo stopped n = trivial $ cmdProperty "systemctl" ["stop", n] `describe` ("service " ++ n ++ " stopped") -- | Enables a systemd service. -enabled :: ServiceName -> Property +enabled :: ServiceName -> Property NoInfo enabled n = trivial $ cmdProperty "systemctl" ["enable", n] `describe` ("service " ++ n ++ " enabled") -- | Disables a systemd service. -disabled :: ServiceName -> Property +disabled :: ServiceName -> Property NoInfo disabled n = trivial $ cmdProperty "systemctl" ["disable", n] `describe` ("service " ++ n ++ " disabled") -- | Restarts a systemd service. -restarted :: ServiceName -> Property +restarted :: ServiceName -> Property NoInfo restarted n = trivial $ cmdProperty "systemctl" ["restart", n] `describe` ("service " ++ n ++ " restarted") -- | Enables persistent storage of the journal. -persistentJournal :: Property +persistentJournal :: Property NoInfo persistentJournal = check (not <$> doesDirectoryExist dir) $ combineProperties "persistent systemd journal" [ cmdProperty "install" ["-d", "-g", "systemd-journal", dir] @@ -89,7 +89,7 @@ type Option = String -- This assumes that there is only one [Header] per file, which is -- currently the case. And it assumes the file already exists with -- the right [Header], so new lines can just be appended to the end. -configured :: FilePath -> Option -> String -> Property +configured :: FilePath -> Option -> String -> Property NoInfo configured cfgfile option value = combineProperties desc [ File.fileProperty desc (mapMaybe removeother) cfgfile , File.containsLine cfgfile line @@ -103,13 +103,13 @@ configured cfgfile option value = combineProperties desc | otherwise = Just l -- | Configures journald, restarting it so the changes take effect. -journaldConfigured :: Option -> String -> Property +journaldConfigured :: Option -> String -> Property NoInfo journaldConfigured option value = configured "/etc/systemd/journald.conf" option value `onChange` restarted "systemd-journald" -- | Causes systemd to reload its configuration files. -daemonReloaded :: Property +daemonReloaded :: Property NoInfo daemonReloaded = trivial $ cmdProperty "systemctl" ["daemon-reload"] -- | Defines a container with a given machine name. @@ -143,17 +143,12 @@ container name mkchroot = Container name c h -- and deletes the chroot and all its contents. nspawned :: Container -> RevertableProperty nspawned c@(Container name (Chroot.Chroot loc system builderconf _) h) = - RevertableProperty setup teardown + p `describe` ("nspawned " ++ name) where - setup = combineProperties ("nspawned " ++ name) $ - map toProp steps ++ [containerprovisioned] - teardown = combineProperties ("not nspawned " ++ name) $ - map (toProp . revert) (reverse steps) - steps = - [ enterScript c - , chrootprovisioned - , nspawnService c (_chrootCfg $ _chrootinfo $ hostInfo h) - ] + p = enterScript c + `before` chrootprovisioned + `before` nspawnService c (_chrootCfg $ _chrootinfo $ hostInfo h) + `before` containerprovisioned -- Chroot provisioning is run in systemd-only mode, -- which sets up the chroot and ensures systemd and dbus are @@ -163,15 +158,17 @@ nspawned c@(Container name (Chroot.Chroot loc system builderconf _) h) = -- Use nsenter to enter container and and run propellor to -- finish provisioning. - containerprovisioned = Chroot.propellChroot chroot - (enterContainerProcess c) False + containerprovisioned = + Chroot.propellChroot chroot (enterContainerProcess c) False + + doNothing chroot = Chroot.Chroot loc system builderconf h -- | Sets up the service file for the container, and then starts -- it running. nspawnService :: Container -> ChrootCfg -> RevertableProperty -nspawnService (Container name _ _) cfg = RevertableProperty setup teardown +nspawnService (Container name _ _) cfg = setup teardown where service = nspawnServiceName name servicefile = "/etc/systemd/system/multi-user.target.wants" service @@ -215,7 +212,7 @@ nspawnServiceParams (SystemdNspawnCfg ps) = -- This uses nsenter to enter the container, by looking up the pid of the -- container's init process and using its namespace. enterScript :: Container -> RevertableProperty -enterScript c@(Container name _ _) = RevertableProperty setup teardown +enterScript c@(Container name _ _) = setup teardown where setup = combineProperties ("generated " ++ enterScriptFile c) [ scriptfile `File.hasContent` -- cgit v1.2.3