more systemd improvements
This commit is contained in:
parent
765367dab9
commit
c9dc306016
|
@ -2,14 +2,17 @@
|
||||||
|
|
||||||
module Propellor.Property.Systemd (
|
module Propellor.Property.Systemd (
|
||||||
-- * Services
|
-- * Services
|
||||||
module Propellor.Property.Systemd.Core,
|
|
||||||
ServiceName,
|
ServiceName,
|
||||||
started,
|
started,
|
||||||
stopped,
|
stopped,
|
||||||
enabled,
|
enabled,
|
||||||
disabled,
|
disabled,
|
||||||
|
running,
|
||||||
restarted,
|
restarted,
|
||||||
|
networkd,
|
||||||
|
journald,
|
||||||
-- * Configuration
|
-- * Configuration
|
||||||
|
installed,
|
||||||
Option,
|
Option,
|
||||||
configured,
|
configured,
|
||||||
daemonReloaded,
|
daemonReloaded,
|
||||||
|
@ -61,6 +64,9 @@ instance PropAccum Container where
|
||||||
getProperties (Container _ _ h) = hostProperties h
|
getProperties (Container _ _ h) = hostProperties h
|
||||||
|
|
||||||
-- | Starts a systemd service.
|
-- | Starts a systemd service.
|
||||||
|
--
|
||||||
|
-- Note that this does not configure systemd to start the service on boot,
|
||||||
|
-- it only ensures that the service is currently running.
|
||||||
started :: ServiceName -> Property NoInfo
|
started :: ServiceName -> Property NoInfo
|
||||||
started n = trivial $ cmdProperty "systemctl" ["start", n]
|
started n = trivial $ cmdProperty "systemctl" ["start", n]
|
||||||
`describe` ("service " ++ n ++ " started")
|
`describe` ("service " ++ n ++ " started")
|
||||||
|
@ -71,6 +77,9 @@ stopped n = trivial $ cmdProperty "systemctl" ["stop", n]
|
||||||
`describe` ("service " ++ n ++ " stopped")
|
`describe` ("service " ++ n ++ " stopped")
|
||||||
|
|
||||||
-- | Enables a systemd service.
|
-- | Enables a systemd service.
|
||||||
|
--
|
||||||
|
-- This does not ensure the service is started, it only configures systemd
|
||||||
|
-- to start it on boot.
|
||||||
enabled :: ServiceName -> Property NoInfo
|
enabled :: ServiceName -> Property NoInfo
|
||||||
enabled n = trivial $ cmdProperty "systemctl" ["enable", n]
|
enabled n = trivial $ cmdProperty "systemctl" ["enable", n]
|
||||||
`describe` ("service " ++ n ++ " enabled")
|
`describe` ("service " ++ n ++ " enabled")
|
||||||
|
@ -80,11 +89,23 @@ disabled :: ServiceName -> Property NoInfo
|
||||||
disabled n = trivial $ cmdProperty "systemctl" ["disable", n]
|
disabled n = trivial $ cmdProperty "systemctl" ["disable", n]
|
||||||
`describe` ("service " ++ n ++ " disabled")
|
`describe` ("service " ++ n ++ " disabled")
|
||||||
|
|
||||||
|
-- | Ensures that a service is both enabled and started
|
||||||
|
running :: ServiceName -> Property NoInfo
|
||||||
|
running n = trivial $ started n `requires` enabled n
|
||||||
|
|
||||||
-- | Restarts a systemd service.
|
-- | Restarts a systemd service.
|
||||||
restarted :: ServiceName -> Property NoInfo
|
restarted :: ServiceName -> Property NoInfo
|
||||||
restarted n = trivial $ cmdProperty "systemctl" ["restart", n]
|
restarted n = trivial $ cmdProperty "systemctl" ["restart", n]
|
||||||
`describe` ("service " ++ n ++ " restarted")
|
`describe` ("service " ++ n ++ " restarted")
|
||||||
|
|
||||||
|
-- | The systemd-networkd service.
|
||||||
|
networkd :: ServiceName
|
||||||
|
networkd = "systemd-networkd"
|
||||||
|
|
||||||
|
-- | The systemd-journald service.
|
||||||
|
journald :: ServiceName
|
||||||
|
journald = "systemd-journald"
|
||||||
|
|
||||||
-- | Enables persistent storage of the journal.
|
-- | Enables persistent storage of the journal.
|
||||||
persistentJournal :: Property NoInfo
|
persistentJournal :: Property NoInfo
|
||||||
persistentJournal = check (not <$> doesDirectoryExist dir) $
|
persistentJournal = check (not <$> doesDirectoryExist dir) $
|
||||||
|
@ -118,15 +139,15 @@ configured cfgfile option value = combineProperties desc
|
||||||
| setting `isPrefixOf` l = Nothing
|
| setting `isPrefixOf` l = Nothing
|
||||||
| otherwise = Just l
|
| otherwise = Just l
|
||||||
|
|
||||||
|
-- | Causes systemd to reload its configuration files.
|
||||||
|
daemonReloaded :: Property NoInfo
|
||||||
|
daemonReloaded = trivial $ cmdProperty "systemctl" ["daemon-reload"]
|
||||||
|
|
||||||
-- | Configures journald, restarting it so the changes take effect.
|
-- | Configures journald, restarting it so the changes take effect.
|
||||||
journaldConfigured :: Option -> String -> Property NoInfo
|
journaldConfigured :: Option -> String -> Property NoInfo
|
||||||
journaldConfigured option value =
|
journaldConfigured option value =
|
||||||
configured "/etc/systemd/journald.conf" option value
|
configured "/etc/systemd/journald.conf" option value
|
||||||
`onChange` restarted "systemd-journald"
|
`onChange` restarted journald
|
||||||
|
|
||||||
-- | Causes systemd to reload its configuration files.
|
|
||||||
daemonReloaded :: Property NoInfo
|
|
||||||
daemonReloaded = trivial $ cmdProperty "systemctl" ["daemon-reload"]
|
|
||||||
|
|
||||||
-- | Defines a container with a given machine name.
|
-- | Defines a container with a given machine name.
|
||||||
--
|
--
|
||||||
|
@ -320,13 +341,24 @@ instance Publishable (Proto, Bound Port) where
|
||||||
toPublish (TCP, fp) = "tcp:" ++ toPublish fp
|
toPublish (TCP, fp) = "tcp:" ++ toPublish fp
|
||||||
toPublish (UDP, fp) = "udp:" ++ toPublish fp
|
toPublish (UDP, fp) = "udp:" ++ toPublish fp
|
||||||
|
|
||||||
-- | Publish a port from the container on the host.
|
-- | Publish a port from the container to the host.
|
||||||
--
|
--
|
||||||
-- Note that this will only work if the container is set up to use
|
|
||||||
-- private networking. If the container does not use private networking,
|
|
||||||
-- this property is not needed.
|
|
||||||
--
|
|
||||||
-- This feature was first added in systemd version 220.
|
-- This feature was first added in systemd version 220.
|
||||||
|
--
|
||||||
|
-- This property is only needed (and will only work) if the container
|
||||||
|
-- is configured private networking. Also, networkd should be enabled
|
||||||
|
-- both inside the container, and on the host. For example:
|
||||||
|
--
|
||||||
|
-- > foo :: Host
|
||||||
|
-- > foo = host "foo.example.com"
|
||||||
|
-- > & Systemd.running Systemd.networkd
|
||||||
|
-- > & Systemd.nspawned webserver
|
||||||
|
-- >
|
||||||
|
-- > webserver :: Systemd.container
|
||||||
|
-- > webserver = Systemd.container "webserver" (Chroot.debootstrapped (System (Debian Testing) "amd64") mempty)
|
||||||
|
-- > & Systemd.running Systemd.networkd
|
||||||
|
-- > & Systemd.publish (Port 80 ->- Port 8080)
|
||||||
|
-- > & Apt.installedRunning "apache2"
|
||||||
publish :: Publishable p => p -> RevertableProperty
|
publish :: Publishable p => p -> RevertableProperty
|
||||||
publish p = containerCfg $ "--port=" ++ toPublish p
|
publish p = containerCfg $ "--port=" ++ toPublish p
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue