aboutsummaryrefslogtreecommitdiff
path: root/manifests/vserver/instance.pp
diff options
context:
space:
mode:
Diffstat (limited to 'manifests/vserver/instance.pp')
-rw-r--r--manifests/vserver/instance.pp89
1 files changed, 89 insertions, 0 deletions
diff --git a/manifests/vserver/instance.pp b/manifests/vserver/instance.pp
new file mode 100644
index 0000000..3ec9130
--- /dev/null
+++ b/manifests/vserver/instance.pp
@@ -0,0 +1,89 @@
+define virtual::vserver::instance(
+ $in_domain,
+ $context,
+ $legacy = false,
+ $distro = 'jessie',
+ $debootstrap_mirror = 'http://cdn.debian.net/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 }
+
+ case $vs_name { '': { fail ( "Cannot create VServer with empty name" ) } }
+
+ case $legacy {
+ true: {
+ exec { "/bin/false # cannot create legacy vserver ${vs_name}":
+ creates => "/etc/vservers/${vs_name}",
+ alias => "vserver_instance_${vs_name}"
+ }
+ }
+ false: {
+ 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","/etc/vservers/.defaults/vdirbase"],
+ alias => "vserver_instance_${vs_name}",
+ # TODO: change when this is fixed: http://projects.puppetlabs.com/issues/4769
+ timeout => $lsbdistcodename ? {
+ "squeeze" => '31536000', # 1 year
+ default => '-1', },
+ }
+ }
+ }
+
+ file { "/etc/vservers/${vs_name}/rlimits":
+ ensure => directory,
+ mode => 0755,
+ owner => root,
+ group => root,
+ require => Exec["vserver_instance_${vs_name}"],
+ }
+
+ case $memory_limit {
+ false: {
+ file { "/etc/vservers/${vs_name}/rlimits/rss.hard":
+ mode => 0644, owner => root, group => root,
+ ensure => absent,
+ }
+
+ file { "/etc/vservers/${vs_name}/rlimits/rss.soft":
+ mode => 0644, owner => root, group => root,
+ ensure => absent,
+ }
+
+ virtual::vserver::cflags { "${vs_name}-virt_mem":
+ vserver => $vs_name,
+ flag => "virt_mem",
+ ensure => absent,
+ }
+ }
+ default: {
+ 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"],
+ }
+
+ vs_cflags { "${vs_name}-virt_mem":
+ vserver => $vs_name,
+ flag => "virt_mem",
+ ensure => present,
+ require => Exec["vserver_instance_${vs_name}"],
+ }
+ }
+ }
+}
+