aboutsummaryrefslogtreecommitdiff
path: root/manifests/vserver/instance.pp
blob: a994d1c134c880c14bbf777fedc044ff6f41b4c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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}"],
  }

  file { "/etc/vservers/${vs_name}/rlimits/rss.hard":
    mode    => '0644',
    owner   => root,
    group   => root,
    content => template("virtual/rss.hard.erb"),
    require => $memory_limit ? {
      false   => undef,
      default => File["/etc/vservers/${vs_name}/rlimits"],
    },
    ensure  => $memory_limit ? {
      false   => absent,
      default => present,
    },
  }

  file { "/etc/vservers/${vs_name}/rlimits/rss.soft":
    mode    => '0644',
    owner   => root,
    group   => root,
    content => template("virtual/rss.soft.erb"),
    require => $memory_limit ? {
      false   => undef,
      default => File["/etc/vservers/${vs_name}/rlimits"],
    },
    ensure  => $memory_limit ? {
      false   => absent,
      default => present,
    },
  }

  virtual::vserver::cflags { "${vs_name}-virt_mem":
    vserver => $vs_name,
    flag    => "virt_mem",
    require => $memory_limit ? {
      false   => undef,
      default => Exec["vserver_instance_${vs_name}"],
    },
    ensure  => $memory_limit ? {
      false   => absent,
      default => present,
    },
  }
}