aboutsummaryrefslogtreecommitdiff
path: root/manifests/vserver.pp
blob: a963b9f08b99c0596d79863e611eccbafe16a415 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
class nodo::vserver inherits nodo {
  include sshd
  include timezone
  include syslog-ng::vserver

  backupninja::sys { "sys":
    ensure     => present,
    partitions => false,
    hardware   => false,
    dosfdisk   => false,
    dohwinfo   => false,
  }

  $hosting_type = $node_hosting_type ? {
    ''      => "direct",
    default => "$node_hosting_type",
  }

  case $hosting_type {
    "direct": {
      # Apply munin and monkeysphere configuration for
      # for directly hosted nodes.
      Munin_node        <<| title == $hostname |>>
      Monkeysphere_host <<| title == $hostname |>>
    }
    "third-party": {
      # Apply munin configuration for this node for third-party
      # hosted nodes.
      munin_node { "$hostname": }
      monkeysphere_host { "$hostname":
        port => $node_ssh_port,
      }
    }
  }

  # Define a vserver instance
  define instance($context, $ensure = 'running', $proxy = false,
                  $puppetmaster = false, $gitd = false, $mail = false,
                  $icecast = false, $sound = false, $ticket = false,
                  $memory_limit = false, $distro = 'lenny') {

    # set instance id
    if $context <= 9 {
      $id = "0$context"
    } else {
      $id = $context
    }

    # set puppetmaster ssl port
    case $puppetmaster_port {
      '': { $puppetmaster_port = "8140" }
    }

    # set puppetmaster non-ssl port
    case $puppetmaster_nonssl_port {
      '': { $puppetmaster_nonssl_port = "8141" }
    }

    vserver { $name:
      ensure       => $ensure,
      context      => "$context",
      mark         => 'default',
      distro       => $distro,
      interface    => "eth0:192.168.0.$context/24",
      hostname     => "$name.$domain",
      memory_limit => $memory_limit,
    }

    # Some nodes need a lot of space at /tmp otherwise some admin
    # tasks like backups might not run.
    file { "/etc/vservers/${name}/fstab":
      source  => [ "puppet:///modules/site-nodo/etc/fstab/vserver/$name",
                   "puppet:///modules/nodo/etc/fstab/vserver" ],
      owner   => "root",
      group   => "root",
      mode    => 0644,
      ensure  => present,
      notify  => Exec["vs_restart_${name}"],
      require => Exec["vs_create_${name}"],
    }

    # Create a munin virtual resource to be realized in the node
    @@munin_node { "$name":
      port => "49$id",
    }

    # Create a monkeysphere virtual resource to be realized in the node
    @@monkeysphere_host { "$name":
      port => "22$id",
    }

    # Sound support
    if $sound {
      if !defined(File["/usr/local/sbin/create-sound-devices"]) {
        file { "/usr/local/sbin/create-sound-devices":
          ensure => present,
          source => "puppet:///modules/nodo/sound/devices.sh",
          owner  => root,
          group  => root,
          mode   => 755,
        }
      }
      exec { "/usr/local/sbin/create-sound-devices ${name}":
        unless  => "/usr/local/sbin/create-sound-devices ${name} --check",
        user    => root,
        require => [ Exec["vs_create_${name}"], File["/usr/local/sbin/create-sound-devices"] ],
      }
    }

    # Apply firewall rules just for running vservers
    case $ensure {
      'running': {
        firewall::router::ssh { "ssh-$name":
          destination => "192.168.0.$context",
          port_orig   => "22",
          port_dest   => "22$id",
        }

        firewall::router::munin { "munin-$name":
          destination => "192.168.0.$context",
          port_orig   => "49$id",
          port_dest   => "49$id",
        }

        if $proxy {
          class {
            "firewall::router::http":  destination => "192.168.0.$context";
            "firewall::router::https": destination => "192.168.0.$context";
          }
        }

        if $puppetmaster {
          class {
            "firewall::router::puppetmaster":
              destination              => "192.168.0.$context",
              puppetmaster_port        => $puppetmaster_port,
              puppetmaster_nonssl_port => $puppetmaster_nonssl_port,
          }
        }

        if $gitd {
          class {
            "firewall::router::gitd": destination => "192.168.0.$context";
          }
        }

        if $icecast {
          class {
            "firewall::router::icecast": destination => "192.168.0.$context";
          }
        }

        if $mail {
          class {
            "firewall::router::mail": destination => "192.168.0.$context";
          }
        }
      }
    }
  }
}