diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2015-03-24 15:36:27 -0300 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2015-03-24 15:36:27 -0300 |
commit | becba25bf7e547f3550ce05fb1aeb9c8f9283135 (patch) | |
tree | 98299ec9460d952d24df09ce1c52f72d7e153bf4 /manifests/vserver/create.pp | |
parent | c2e477d0a8667bc3a983105421d5c048faa31661 (diff) | |
download | puppet-virtual-becba25bf7e547f3550ce05fb1aeb9c8f9283135.tar.gz puppet-virtual-becba25bf7e547f3550ce05fb1aeb9c8f9283135.tar.bz2 |
Autoload for vserver
Diffstat (limited to 'manifests/vserver/create.pp')
-rw-r--r-- | manifests/vserver/create.pp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/manifests/vserver/create.pp b/manifests/vserver/create.pp new file mode 100644 index 0000000..6a6924b --- /dev/null +++ b/manifests/vserver/create.pp @@ -0,0 +1,75 @@ +define virtual::vserver::create($in_domain, $context, $legacy = false, $distro = 'squeeze', + $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 => "vs_create_${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 => "vs_create_${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["vs_create_${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::flag { "${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"], + } + + virtual::vserver::flag { "${vs_name}-virt_mem": + vserver => $vs_name, + flag => "virt_mem", + ensure => present, + require => Exec["vs_create_${vs_name}"], + } + } + } +} |