propellor spin

This commit is contained in:
Joey Hess 2014-11-21 12:35:07 -04:00
parent 976afedea3
commit ae6a5e815c
Failed to extract signature
1 changed files with 26 additions and 5 deletions

View File

@ -1,5 +1,8 @@
module Propellor.Property.Systemd ( module Propellor.Property.Systemd (
installed, installed,
started,
stopped,
enabled,
persistentJournal, persistentJournal,
Container, Container,
container, container,
@ -15,6 +18,8 @@ import Utility.FileMode
import Data.List.Utils import Data.List.Utils
type ServiceName = String
type MachineName = String type MachineName = String
type NspawnParam = CommandParam type NspawnParam = CommandParam
@ -32,12 +37,28 @@ instance Hostlike Container where
installed :: Property installed :: Property
installed = Apt.installed ["systemd", "dbus"] installed = Apt.installed ["systemd", "dbus"]
-- | Starts a systemd service.
started :: ServiceName -> Property
started n = trivial $ cmdProperty "systemctl" ["start", n]
`describe` ("service " ++ n ++ " started")
-- | Stops a systemd service.
stopped :: ServiceName -> Property
stopped n = trivial $ cmdProperty "systemctl" ["stop", n]
`describe` ("service " ++ n ++ " stopped")
-- | Enables a systemd service.
enabled :: ServiceName -> Property
enabled n = trivial $ cmdProperty "systemctl" ["enable", n]
`describe` ("service " ++ n ++ " enabled")
-- | Enables persistent storage of the journal. -- | Enables persistent storage of the journal.
persistentJournal :: Property persistentJournal :: Property
persistentJournal = check (not <$> doesDirectoryExist dir) $ persistentJournal = check (not <$> doesDirectoryExist dir) $
combineProperties "persistent systetemd journal" combineProperties "persistent systemd journal"
[ cmdProperty "install" ["-d", "-g", "systemd-journal", dir] [ cmdProperty "install" ["-d", "-g", "systemd-journal", dir]
, cmdProperty "setfacl" ["-R", "-nm", "g:adm:rx,d:g:adm:rx", dir] , cmdProperty "setfacl" ["-R", "-nm", "g:adm:rx,d:g:adm:rx", dir]
, started "systemd-journal-flush"
] ]
`requires` Apt.installed ["acl"] `requires` Apt.installed ["acl"]
where where
@ -99,8 +120,8 @@ nspawnService (Container name _ ps _) = RevertableProperty setup teardown
setup = check (not <$> doesFileExist servicefile) $ setup = check (not <$> doesFileExist servicefile) $
combineProperties ("container running " ++ service) combineProperties ("container running " ++ service)
[ cmdProperty "systemctl" ["enable", service] [ enabled service
, cmdProperty "systemctl" ["start", service] , started service
] ]
-- TODO ^ adjust execStart line to reflect ps -- TODO ^ adjust execStart line to reflect ps
@ -136,11 +157,11 @@ enterScriptFile (Container name _ _ _ ) = "enter-" ++ mungename name
enterContainerProcess :: Container -> [String] -> CreateProcess enterContainerProcess :: Container -> [String] -> CreateProcess
enterContainerProcess = proc . enterScriptFile enterContainerProcess = proc . enterScriptFile
nspawnServiceName :: MachineName -> String nspawnServiceName :: MachineName -> ServiceName
nspawnServiceName name = "systemd-nspawn@" ++ name ++ ".service" nspawnServiceName name = "systemd-nspawn@" ++ name ++ ".service"
containerDir :: MachineName -> FilePath containerDir :: MachineName -> FilePath
containerDir name = "/var/lib/container" ++ mungename name containerDir name = "/var/lib/container" </> mungename name
mungename :: MachineName -> String mungename :: MachineName -> String
mungename = replace "/" "_" mungename = replace "/" "_"