    module Propellor.Property.Journald where

    import Propellor.Base
    import qualified Propellor.Property.Systemd as Systemd
    import Utility.DataUnits

    -- | Configures journald, restarting it so the changes take effect.
    configured :: Systemd.Option -> String -> Property Linux
    configured :: Option -> Option -> Property Linux
    configured option :: Option
    option value :: Option
    value =
    	Option -> Option -> Option -> Property Linux
    Systemd.configured "/etc/systemd/journald.conf" Option
    option Option
    value
    		Property Linux
    -> Property Linux -> CombinedType (Property Linux) (Property Linux)
    forall x y. Combines x y => x -> y -> CombinedType x y
    `onChange` Option -> Property Linux
    Systemd.restarted "systemd-journald"

    -- The string is parsed to get a data size.
    -- Examples: "100 megabytes" or "0.5tb"
    type DataSize = String

    configuredSize :: Systemd.Option -> DataSize -> Property Linux
    configuredSize :: Option -> Option -> Property Linux
    configuredSize option :: Option
    option s :: Option
    s = case [Unit] -> Option -> Maybe ByteSize
    readSize [Unit]
    dataUnits Option
    s of
    	Just sz :: ByteSize
    sz -> Option -> Option -> Property Linux
    configured Option
    option (ByteSize -> Option
    systemdSizeUnits ByteSize
    sz)
    	Nothing -> Option -> Propellor Result -> Property Linux
    forall k (metatypes :: k).
    SingI metatypes =>
    Option -> Propellor Result -> Property (MetaTypes metatypes)
    property ("unable to parse " Option -> Option -> Option
    forall a. [a] -> [a] -> [a]
    ++ Option
    option Option -> Option -> Option
    forall a. [a] -> [a] -> [a]
    ++ " data size " Option -> Option -> Option
    forall a. [a] -> [a] -> [a]
    ++ Option
    s) (Propellor Result -> Property Linux)
    -> Propellor Result -> Property Linux
    forall a b. (a -> b) -> a -> b
    $
    		Result -> Propellor Result
    forall (m :: * -> *) a. Monad m => a -> m a
    return Result
    FailedChange

    systemMaxUse :: DataSize -> Property Linux
    systemMaxUse :: Option -> Property Linux
    systemMaxUse = Option -> Option -> Property Linux
    configuredSize "SystemMaxUse"

    runtimeMaxUse :: DataSize -> Property Linux
    runtimeMaxUse :: Option -> Property Linux
    runtimeMaxUse = Option -> Option -> Property Linux
    configuredSize "RuntimeMaxUse"

    systemKeepFree :: DataSize -> Property Linux
    systemKeepFree :: Option -> Property Linux
    systemKeepFree = Option -> Option -> Property Linux
    configuredSize "SystemKeepFree"

    runtimeKeepFree :: DataSize -> Property Linux
    runtimeKeepFree :: Option -> Property Linux
    runtimeKeepFree = Option -> Option -> Property Linux
    configuredSize "RuntimeKeepFree"

    systemMaxFileSize :: DataSize -> Property Linux
    systemMaxFileSize :: Option -> Property Linux
    systemMaxFileSize = Option -> Option -> Property Linux
    configuredSize "SystemMaxFileSize"

    runtimeMaxFileSize :: DataSize -> Property Linux
    runtimeMaxFileSize :: Option -> Property Linux
    runtimeMaxFileSize = Option -> Option -> Property Linux
    configuredSize "RuntimeMaxFileSize"

    -- Generates size units as used in journald.conf.
    systemdSizeUnits :: Integer -> String
    systemdSizeUnits :: ByteSize -> Option
    systemdSizeUnits sz :: ByteSize
    sz = (Char -> Bool) -> Option -> Option
    forall a. (a -> Bool) -> [a] -> [a]
    filter (Char -> Char -> Bool
    forall a. Eq a => a -> a -> Bool
    /= ' ') ([Unit] -> Bool -> ByteSize -> Option
    roughSize [Unit]
    cfgfileunits Bool
    True ByteSize
    sz)
      where
    	cfgfileunits :: [Unit]
    	cfgfileunits :: [Unit]
    cfgfileunits =
    	        [ ByteSize -> Option -> Option -> Unit
    Unit (ByteSize -> ByteSize
    p 6) "E" "exabyte"
    		, ByteSize -> Option -> Option -> Unit
    Unit (ByteSize -> ByteSize
    p 5) "P" "petabyte"
    		, ByteSize -> Option -> Option -> Unit
    Unit (ByteSize -> ByteSize
    p 4) "T" "terabyte"
    		, ByteSize -> Option -> Option -> Unit
    Unit (ByteSize -> ByteSize
    p 3) "G" "gigabyte"
    		, ByteSize -> Option -> Option -> Unit
    Unit (ByteSize -> ByteSize
    p 2) "M" "megabyte"
    		, ByteSize -> Option -> Option -> Unit
    Unit (ByteSize -> ByteSize
    p 1) "K" "kilobyte"
    		]
            p :: Integer -> Integer
            p :: ByteSize -> ByteSize
    p n :: ByteSize
    n = 1024ByteSize -> ByteSize -> ByteSize
    forall a b. (Num a, Integral b) => a -> b -> a
    ^ByteSize
    n