]> gitweb.fluxo.info Git - puppet-virtual.git/commitdiff
Adding vserver memory limit. PAGESIZE is hard coded\!
authordrebs <drebs@riseup.net>
Sun, 14 Mar 2010 21:40:26 +0000 (18:40 -0300)
committerdrebs <drebs@riseup.net>
Sun, 14 Mar 2010 21:40:26 +0000 (18:40 -0300)
manifests/vserver.pp
templates/rss.hard.erb [new file with mode: 0644]
templates/rss.soft.erb [new file with mode: 0644]

index b7d2c988f15060f6c554575d932661dbb3d6f0f1..55e68416528e615f089cdcde3667068899efac10 100644 (file)
@@ -116,7 +116,9 @@ class vserver::host {
 }
 
 define vs_create($in_domain, $context, $legacy = false, $distro = 'etch',
-                 $debootstrap_mirror = 'http://ftp.debian.org/debian', $hostname = false, $interface = false) { 
+                 $debootstrap_mirror = 'http://ftp.debian.org/debian',
+                 $hostname = false, $interface = false,
+                 $memory_limit = false) { 
   $vs_name      = $legacy    ? { true  => $name, false => $in_domain ? { '' => $name, default => "${name}.${in_domain}" } }
   $vs_hostname  = $hostname  ? { false => 'none', default => $hostname }
   $vs_interface = $interface ? { false => 'none', default => $interface }
@@ -131,7 +133,7 @@ define vs_create($in_domain, $context, $legacy = false, $distro = 'etch',
       }
     }
     false: {
-      exec { "/usr/local/bin/build_vserver \"${vs_name}\" ${context} ${distro} ${debootstrap_mirror} ${vs_hostname} ${vs_interface}":
+      exec { "/usr/local/bin/build_vserver \"${vs_name}\" ${context} ${distro} ${debootstrap_mirror} ${vs_hostname} ${vs_interface} ${memory_limit}":
         creates => "/etc/vservers/${vs_name}",
         require => File["/usr/local/bin/build_vserver"],
         alias   => "vs_create_${vs_name}",
@@ -139,11 +141,31 @@ define vs_create($in_domain, $context, $legacy = false, $distro = 'etch',
       }
     }
   }
+
+  case $memory_limit {
+    false: { }
+    default: {
+      file { "/etc/vservers/${vs_name}/rlimits":
+        ensure => directory,
+        mode => 0755, owner => root, group => root,
+      }
+      file { "/etc/vservers/${vs_name}/rlimits/rss.hard":
+        mode => 0644, owner => root, group => root,
+        content => template("virtual/rss.hard.erb"),
+        require => File['/etc/vservers/${vs_name}/rlimits'],
+      }
+      file { "/etc/vservers/${vs_name}/rlimits/rss.soft":
+        mode => 0644, owner => root, group => root,
+        content => template("virtual/rss.soft.erb"),
+        require => File['/etc/vservers/${vs_name}/rlimits'],
+      }
+    }
+  }
 }
 
 # ensure: present, stopped, running
 define vserver($ensure, $context, $in_domain = '', $mark = '', $legacy = false, $distro = 'etch',
-               $hostname = false, $interface = false) {
+               $hostname = false, $interface = false, $memory_limit = false) {
   case $in_domain { '': {} 
     default: { err("${fqdn}: vserver ${name} uses deprecated \$in_domain" ) }
   }
@@ -160,42 +182,46 @@ define vserver($ensure, $context, $in_domain = '', $mark = '', $legacy = false,
   case $ensure {
     present: {
                vs_create{ $name:
-                 in_domain => $in_domain,
-                 context   => $context,
-                 legacy    => $legacy,
-                 distro    => $distro,
-                 hostname  => $hostname,
-                 interface => $interface,
+                 in_domain    => $in_domain,
+                 context      => $context,
+                 legacy       => $legacy,
+                 distro       => $distro,
+                 hostname     => $hostname,
+                 interface    => $interface,
+                 memory_limit => $memory_limit,
                }
              }
     running: {
                vs_create{ $name:
-                 in_domain => $in_domain,
-                 context   => $context,
-                 legacy    => $legacy,
-                 distro    => $distro,
-                 hostname  => $hostname,
-                 interface => $interface,
+                 in_domain    => $in_domain,
+                 context      => $context,
+                 legacy       => $legacy,
+                 distro       => $distro,
+                 hostname     => $hostname,
+                 interface    => $interface,
+                 memory_limit => $memory_limit,
                }
              }
     stopped: {
                vs_create{ $name:
-                 in_domain => $in_domain,
-                 context   => $context,
-                 legacy    => $legacy,
-                 distro    => $distro,
-                 hostname  => $hostname,
-                 interface => $interface,
+                 in_domain    => $in_domain,
+                 context      => $context,
+                 legacy       => $legacy,
+                 distro       => $distro,
+                 hostname     => $hostname,
+                 interface    => $interface,
+                 memory_limit => $memory_limit,
                }
              }
     delete: {
                vs_create{ $name:
-                 in_domain => $in_domain,
-                 context   => $context,
-                 legacy    => $legacy,
-                 distro    => $distro,
-                 hostname  => $hostname,
-                 interface => $interface,
+                 in_domain    => $in_domain,
+                 context      => $context,
+                 legacy       => $legacy,
+                 distro       => $distro,
+                 hostname     => $hostname,
+                 interface    => $interface,
+                 memory_limit => $memory_limit,
                }
              }
     default: {
diff --git a/templates/rss.hard.erb b/templates/rss.hard.erb
new file mode 100644 (file)
index 0000000..f806702
--- /dev/null
@@ -0,0 +1 @@
+<%= memory_limit * 1_000_000 / 4096 %>
diff --git a/templates/rss.soft.erb b/templates/rss.soft.erb
new file mode 100644 (file)
index 0000000..f806702
--- /dev/null
@@ -0,0 +1 @@
+<%= memory_limit * 1_000_000 / 4096 %>