From c224625734fb4b6ae11f6fdd897ed83fc7f7bab5 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 1 Jun 2014 13:35:21 -0400 Subject: propellor spin --- src/Propellor/Property/Docker.hs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/Propellor/Property') diff --git a/src/Propellor/Property/Docker.hs b/src/Propellor/Property/Docker.hs index fbf34965..adaea548 100644 --- a/src/Propellor/Property/Docker.hs +++ b/src/Propellor/Property/Docker.hs @@ -11,6 +11,7 @@ module Propellor.Property.Docker ( configured, container, docked, + memoryLimited, garbageCollected, Image, ContainerName, @@ -25,6 +26,7 @@ module Propellor.Property.Docker ( volumes_from, workdir, memory, + cpuShares, link, ContainerAlias, -- * Internal use @@ -170,6 +172,20 @@ garbageCollected = propertyList "docker garbage collected" gcimages = property "docker images garbage collected" $ do liftIO $ report <$> (mapM removeImage =<< listImages) +-- | Configures the kernel to respect docker memory limits. +-- +-- This assumes the system boots using grub 2. And that you don't need any +-- other GRUB_CMDLINE_LINUX_DEFAULT settings. +-- +-- Only takes effect after reboot. (Not automated.) +memoryLimited :: Property +memoryLimited = "/etc/default/grub" `File.containsLine` cfg + `describe` "docker memory limited" + `onChange` cmdProperty "update-grub" [] + where + cmdline = "cgroup_enable=memory swapaccount=1" + cfg = "GRUB_CMDLINE_LINUX_DEFAULT=\""++cmdline++"\"" + data Container = Container Image [RunParam] -- | Parameters to pass to `docker run` when creating a container. @@ -220,10 +236,17 @@ workdir :: String -> Property workdir = runProp "workdir" -- | Memory limit for container. ---Format: , where unit = b, k, m or g +-- Format: , where unit = b, k, m or g +-- +-- Note: Only takes effect when the host has the memoryLimited property +-- enabled. memory :: String -> Property memory = runProp "memory" +-- | CPU shares (relative weight). +cpuShares :: Int -> Property +cpuShares = runProp "cpu-shares" . show + -- | Link with another container on the same host. link :: ContainerName -> ContainerAlias -> Property link linkwith calias = genProp "link" $ \hn -> -- cgit v1.2.3